TreeView nodes information (All Nodes)

updown

Member
Joined
Sep 19, 2002
Messages
12
Hi!

Im 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 cant 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

(Im using VB.NET for a week. I was used to work with VB6)
 
Last edited by a moderator:
Cant 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).
 
Originally posted by Thinker
This will work
down to whatever level you have (or until you run out of memory).

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

Ive finished the code but I havent 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 Ive finished the code and tried it for 20 sub levels and it worked with no problem.

I dont have the code in this computer so in a day or two Ill 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