Hi, I have a tree that is bound to an ObservableCollection. The user can drag from the tree to a RadDataGrid. On drop the item is removed from the source collection and the collection is rebound like this. Similarly if the user deletes the row from the grid the object is inserted back into the bound collection. ItemsSource is reset like this:
treeview.ItemsSource = null;
treeview.ItemsSource = myCollection;
When the ItemsSource is reset, the tree collapses as expected. But everything I have tried to re-expand it, appears to do nothing.
My first thought was to use ExpandAll() but I find that it only works at Loaded time.
I tried a few other thinds but my last attempt is to traverse the IntemContainers by handling the ItemContainerGenerator.StatusChanged event, finding the last selected item and setting IsExpanded on each item between the root and the selected item to true. Not only does this not work but when I inspect the IsExpanded value at runtime it is false before setting (as expected) but it is still false even after the statement "IsExpanded = true;" is executed.
The code I use to do this is:
RadTreeViewItem child = rootItem.NextItem;
while (child != null) {
child.IsExpanded = true;
child = child.NextItem;
}
As I said, if child.IsExpanded == false before setting it. It stays false;
I also notice that in the last iteration of the loop child.NextItem does not simply return null but throws a NullReferenceException. I suspect this has to do with virtualization. That's behavior I didn't expect.
Any ideas on what I am doing wrong or what the correct way is to do this?
Thank you,
Paul
treeview.ItemsSource = null;
treeview.ItemsSource = myCollection;
When the ItemsSource is reset, the tree collapses as expected. But everything I have tried to re-expand it, appears to do nothing.
My first thought was to use ExpandAll() but I find that it only works at Loaded time.
I tried a few other thinds but my last attempt is to traverse the IntemContainers by handling the ItemContainerGenerator.StatusChanged event, finding the last selected item and setting IsExpanded on each item between the root and the selected item to true. Not only does this not work but when I inspect the IsExpanded value at runtime it is false before setting (as expected) but it is still false even after the statement "IsExpanded = true;" is executed.
The code I use to do this is:
RadTreeViewItem child = rootItem.NextItem;
while (child != null) {
child.IsExpanded = true;
child = child.NextItem;
}
As I said, if child.IsExpanded == false before setting it. It stays false;
I also notice that in the last iteration of the loop child.NextItem does not simply return null but throws a NullReferenceException. I suspect this has to do with virtualization. That's behavior I didn't expect.
Any ideas on what I am doing wrong or what the correct way is to do this?
Thank you,
Paul