The article here shows how to save state, but it fires them on manual changes, I am trying to detect when this repopulation is going to happen, I have other events unrelated to the UI that are changing the state of the object the treeview is bound to. and would like to be able to detect when that happens.
http://docs.telerik.com/devtools/winforms/treeview/how-to/keep-radtreeview-states-on-reset
the overarching goal here, is to prevent the tree expanded state from resetting when the tree bound data is updated off the control.
4 Answers, 1 is accepted
There are no events that you can use for this. What you should do is to call the method that saves the states before changing the data in all places where you are updating the TreeView in your code.
I hope this information is useful.
Regards,
Dimitar
Progress Telerik
I was afraid you were going to say that, the problem is, the changes to the data are happening outside the context of the UI, so the UI is unaware of when the changes are happening.
So if I can't detect the event, maybe I can mitigate the issue its causing.
I would like to keep the tree expanded, I'm not concerned about the state it was in before the reload, but I want the user to be able to expand and collapse via the UI. (how do I do this?)
I tried, setting e.node.expand() on the nodeformatting event this resolves the issue of the tree collapsing on reset, but also prevents the user from collapsing/expanding the node manually. The eventargs.action always seems to return "unknown" so I can't tell when the action is sent via mouse/keyboard. in any of the events that have the action property in their event args.
I believe I've actually resolve the issue, but I would like a sanity check on this to make sure this won't cause any issues.
Note* ChecklistFilteredTreeView is a control that contains a RadTreeView, and its accessibly as TreeView
my solution, cast the Treeview's datasource back to the type it was when it was set, which in this case is a BindingList, which exposes the events for change, add a handler for that, to expand the nodes when this event is fired.
Again, does this sound like a sound approach?
var foo = ChecklistFilteredTreeView.TreeView.DataSource
as
BindingList<FlatNode>;
foo.ListChanged += (s, eventargs) =>
{
ChecklistFilteredTreeView.TreeView.ExpandAll();
};
This indeed will work. I cannot see any reason not to use it.
Regards,
Dimitar
Progress Telerik