Save TreeView State
So for example, let's say you have a C# program that builds a TreeView programmatically. Since elements are dynamic, the TreeView is cleared and repopulated every time a single Node is changed.
Save TreeView State
The concept is simple: iterate through the top level Nodes of a TreeView and save whether the node was expanded or collapsed. Notice that to keep things simple, the source code only saves the state of top-level nodes:
Code
Load TreeView State
Once the TreeView state is saved, loading the state is just as simple:
Code
The C# functions Expand and Collapse make it simple to set the previous state of the TreeView nodes.