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
Somehow this post was posted twice and I can't find a possibility to delete a post.