Help - Recursively Opening & Closing All Nodes in Treeview

  • Thread starter Thread starter Lanny McDonald
  • Start date Start date
L

Lanny McDonald

I have built a treeview that looks something like:



Root

.....FolderLevel1a

.........FolderLevel2a

.............Page

.........FolderLevel2b

.............Page

.............Page

.....FolderLevel1b

.........FolderLevel2a

.............Page

.............Page

.........FolderLevel2b

.............Page

(etc.)



I now need to write two functions--one that recursively opens all nodes and open that recursively closes all nodes. I've tried, but I can't seem to make much progress.



Has anyone done this? If so, would you provide some guidance? Or, if anyone else has any suggestions, they would be appreciated too.



Thanks.
 
Your recursive probe is simple to setup. First, your outer loop will iterate the collection of nodes. For each node you will call a function to either close or open the node. Pass a flag into that function to tell the routine whether to close or open. That way, you only need one routine which will either close or open. For each node in your iteration, you will call this function. The function will iteratively call itself as long as their are nodes which have children. On each call it will examine the close flag and determine what to do.

Another approach is just to iterate thru the top level nodes and close them. Lower levels don't need to be closed since they cannot be viewed. Opening would need recursion/.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
I have built a treeview that looks something like:



Root

....FolderLevel1a

........FolderLevel2a

............Page

........FolderLevel2b

............Page

............Page

....FolderLevel1b

........FolderLevel2a

............Page

............Page

........FolderLevel2b

............Page

(etc.)



I now need to write two functions--one that recursively opens all nodes and open that recursively closes all nodes. I've tried, but I can't seem to make much progress.



Has anyone done this? If so, would you provide some guidance? Or, if anyone else has any suggestions, they would be appreciated too.



Thanks.
 
Back
Top