detecting when Treeview repopulates itself when bound

5 posts, 0 answers
  1. Bruce
    Bruce avatar
    25 posts
    Member since:
    May 2017

    Posted 26 Jul Link to this post

    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.

  2. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 27 Jul Link to this post

    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.
  3. Bruce
    Bruce avatar
    25 posts
    Member since:
    May 2017

    Posted 27 Jul in reply to Dimitar Link to this post

    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. 

  4. Bruce
    Bruce avatar
    25 posts
    Member since:
    May 2017

    Posted 27 Jul in reply to Bruce Link to this post

    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();
    };
  5. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 28 Jul Link to this post

    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.
Back to Top