Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1270
Store treenode expansion states between reload of nodes?
posted

I have a tree which I need to reload periodically to get updated data and new/deleted/moved nodes.

However each time I show the tree the nodes are collapsed, and it would be nicer for the user to see the tree expanded as it was before (with incorporating any changes with new/deleted/moved nodes).  This is pretty much like the Windows Explorer tree, when another process adds a folder and the tree updates while maintaining the tree node states.

Any tips on how to implement this would be appreciated, other than maintaining all the states myself on expansion state events.

Boz

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Boz,

    The best way to handle this is to avoid completely re-setting the tree's DataSource. If you set the DataSource property on the tree or you do something to the DataSource that causes it to send a Reset notification, then the tree has no choice but to throw away all of it's existing nodes and build a set of new ones based on the new data source.

    If that's not possible, then the only alternative would be to store all of the expanded states yourself based on some primary key data on each node.

Children