TreeListBox clears its selected items when column sorting - can this be avoided?

Grids for WPF Forum

The latest build of this product (v25.1.1) was released 18 days ago, which was before this thread was created.
Posted 10 days ago by Alex George - CNC Software
Version: 25.1.1
Avatar

Hello,
It seems that the TreeListBox clears its selected items when column sorting, from the call to InvalidateChildren(). this can be seen in SampleBrowser example.
This is causing some headache in our implementation, we are trying to reduce property changed events and prevent the tree's SelectedItem from being reset to null, when a user clicks the column.
Are there any solutions we can try to prevent this from happening? We can cache the selected item before InvalidateChildren() and then re-set that item as Selected but this is not ideal for our implementation, we are hoping there might be another way.

Thank you

Comments (2)

Answer - Posted 10 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Alex,

In a recent update, we made it so that changing the ItemsSource (via RootItem) won't clear selection.  This is a little hacky but will work with v25.1.1 in place of the treeListView.InvalidateChildren call at the end of the Sorting sample code:

var oldRootItem = treeListView.RootItem;
treeListView.RootItem = null;
treeListView.RootItem = oldRootItem;

We are also updating the InvalidateChildren method for the next version to retain selection in a similar way so that the Sorting sample code as-is will not clear selection.


Actipro Software Support

Posted 9 days ago by Alex George - CNC Software
Avatar

Thank you, this does seem to do the trick

Add Comment

Please log in to a validated account to post comments.