We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

TreeViewAdv undo selection change in code

Thread ID:

Created:

Updated:

Platform:

Replies:

115609 Jan 24,2014 12:10 PM Feb 3,2014 11:02 PM WPF 4
loading
Tags: Tools
Reinhard Schürer
Asked On January 24, 2014 12:10 PM

Hello

In my project I use the TreeViewAdv control to switch between different projects items which can be edited by the user but before switching I need to validate the input and if a validation error occurs I need to prevent the switch.

As there is no event in TreeViewAdv which allows me to cancel the selection of a new item I instead try to revert the selection back to it's previous state.

In my OnSelectedItemChanged code I try:

myTree.SelectedItems.Clear();
myTree.SelectedTreeItem = oldSelItem;

which causes another SelectedItemChanged event as expected, but after I ignore this and set e.Handled = true I receive another SelectedItemChanged event which has an SelectedItems.Count of 2 and SelectedItems[0] is the oldSelItem and SelectedItems[1] contains the item the user selected previously Again I have to clear the SelectItems and set it to oldSelItem to finally have my old selection back but this behaviour is very strange and complicate to prevent a selection change.

Here the sequence of the events:

TreeViewAdv with current selected item id: 3070

User clicks on item with id 3153 and causes SelectedItemChanged event with item id 3153

Validation of current item (3070) fails and needs to prevent the selection change:

myTree.SelectedItems.Clear();
myTree.SelectedTreeItem = oldSelItem;

SelectedItemChanged event with item id 3070 (as expected)

e.Handled = true;

return;

SelectedItemChanged event with item id 3070 and 3153 (unexpected)

here I need

myTree.SelectedItems.Clear();
myTree.SelectedTreeItem = oldSelItem;

again

SelectedItemChanged event with item id 3070 (as expected) to finally change back to the old item.

Is there a better way to handle this and what causes this strange SelectedItemChanged event?

Regards,

Reinhard


Reinhard Schürer
Replied On January 24, 2014 12:13 PM

Somehow this post was posted twice and I can't find a possibility to delete a post.


Markus Schroeder
Replied On January 29, 2014 05:45 AM

Since I've just had to deal with the Treeview control as well (annoying control in general, not Syncfusion's fault). I am using MVVM but I am sure it's not that much different. Basically you need handle the events of the TreeViewItemAdv control (could be PreviewMouseDown and PreviewKeyDown) and set handled = true. Trying the same events of the TreeViewAdv control is just super annoying and will basically not work without tons of trouble.

Markus Schroeder
Replied On January 29, 2014 05:57 AM

Can't edit posts, I mean the normal non preview events (MouseDown, KeyDown).

Jegan Raj M [Syncfusion]
Replied On February 3, 2014 11:02 PM

Hi Reinhard,

In our current implementation of 'TreeViewAdv' we don't have support for 'SelectionChanging' event to cancel the selected event. If we do work around for this requirement, it will call 'SelectedItemChanged' recursively when we cancel selection. So, we consider this as a feature request and added to our database. Please visit our website periodically for feature related updates.

Please let us know if you need further assistance.

Regards,
Jegan Raj M

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;