TreeView nodes information (All Nodes)

updown

Newcomer
Joined
Sep 19, 2002
Messages
12
Hi!

I'm creating an app witch has a TreeView control named TVC.
At some point I will need to save my app data to a file. My problem is I can't go through all TVC nodes to store them in a file.

I can only access the first set of childnodes in the control. To get over this I started to think of another way of doing this and I came up with this:

Code:
Dim a, b

For a = 1 To TVC.Nodes.Count
    MsgBox(TVC.Nodes.Item(a - 1).Text)
    If TVC.Nodes.Item(a - 1).Nodes.Count > 0 Then
        For b = 1 To TVC.Nodes.Item(a - 1).Nodes.Count
            MsgBox(TVC.Nodes.Item(a - 1).Nodes.Item(b - 1).Text)
        Next
    End If
Next


The code above allow me to store information from the first and second nodes but I will have to limit my controll to a number of sub child nodes.

Can anyone give me a help on this...

Thanks

(I'm using VB.NET for a week. I was used to work with VB6)
 
Last edited:
Can't take the time to write code for you, but you might need a
recursive function that you can pass a node to, and it will process
all the child nodes, calling itself for each child node. This will work
down to whatever level you have (or until you run out of memory).
 
Thinker said:
This will work
down to whatever level you have (or until you run out of memory).

I did'n knew that a funcion could call itself. I'm coding it but do you think that it is possible to run out of memory with about nine or ten levels of childs??
 
Recursion

I've finished the code but I haven't tried it with more than 4 levels. Tomorrow I will try with more levels and then I will say something.
 
The recursive function works great

Ok I've finished the code and tried it for 20 sub levels and it worked with no problem.

I don't have the code in this computer so in a day or two I'll put it here. It might help some other users.

Thanks Thinker for your idea.



"The fear of being free makes the pryde of being slave"
 
Back
Top