Help - Recursively Opening & Closing All Nodes in Treeview

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.
 
A

Alvin Bruney [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top