How can I create a tree of control on my Form ?  
Author Message
mtgRhox





PostPosted: Windows Forms General, How can I create a tree of control on my Form ? Top

Hello.

Well, I have a question.

I want to create a tree of my custom controls on my From, whick must looks like a standard tree view (I want to say that I will be able to show or hide nodes and leafes of my tree). What class, standart control or other things can help me to do it

Thanks for help.



Windows Forms25  
 
 
Alan Robbins





PostPosted: Windows Forms General, How can I create a tree of control on my Form ? Top

What you have to do is iterate over the controls collection recursively, as controls can contain controls. Something like this pseudo code:

Setup the tree with one node (Form) and call Add Node passing the forms control collection (Form.Controls)

Add Node(Tree Node, ControlCollection)

for each control in controlcollection

switch/select the control type and add the appropriate node

if the control is a container control (group box, tab dialog, panel)

call add node (recursively)

...

If you've never done anything like this it can seem like magic but once you've done it a few times it makes sense. If you're completely lost let me know your language preference (VB or C#) and I'll get you started.