This is a migrated thread and some comments may be shown as answers.

detecting when Treeview repopulates itself when bound

4 Answers 61 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 2
Bruce asked on 26 Jul 2017, 09:00 PM

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

Sort by
0
Dimitar
Telerik team
answered on 27 Jul 2017, 08:15 AM
Hello Bruce,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Bruce
Top achievements
Rank 2
answered on 27 Jul 2017, 01:53 PM

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. 

0
Bruce
Top achievements
Rank 2
answered on 27 Jul 2017, 02:17 PM

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();
};
0
Dimitar
Telerik team
answered on 28 Jul 2017, 07:58 AM
Hi Bruce,

This indeed will work. I cannot see any reason not to use it.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Treeview
Asked by
Bruce
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Bruce
Top achievements
Rank 2
Share this question
or