Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview control question

Status
Not open for further replies.

Muddmuse

Programmer
Jul 31, 2001
85
US
Is it possible to maintain the state of a treeview control when it has been re-initialized? In other words, I populate a treeview control, make some changes that require the tree to be reloaded, then when it reloads any nodes that were expanded prior to the reload (or at least the selectedItem node) remain expanded. If this is possible, how do I do it?

Thanks in advance.
 
Well, I would say that it's probably better to not "reload" the treeview but rather to modify the individual nodes ( by referring to their keys )that require it, or to add / delete nodes as needed.

Barring that, you could probably save the key value of the node in in a string variable, and then after the update has taken place, set a node variable to the item with that key value, then set that node's expanded property to true.

Since the control is being reloaded, you can't just set a node variable to the one that was selected, because when the tree is cleared and reloaded they won't be the same object anymore.

If the key value changes after the reload, then that will be a problem as well.

If you aren't setting a value for the key, then you will need to do this.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top