PDA

Click to See Complete Forum and Search --> : Looping all items in a Treeview control


DJ_Catboy
Mar 17th, 2003, 03:57 AM
Hi,

I am relatively new to .NET and am struggling a little with some of the changes from VB6. I programmed version 6 for some years now.

I want to loop through all items in a treeview control. I have found that the nodes collection exists but it doesn't have a count property. Instead, I have found "system.collections.ienumerator" which is what I am supposed to use now, but I can't find any legible help. Can somebody show me a little code that will do what I am after? I would be most grateful.

Thanks in advance,
DJ

Lethal
Mar 18th, 2003, 11:32 PM
I'm not at my dev box right now, but here is a sample recursive routine that would traverse the treeview:


private void TraverseTreeView(TreeNode node)
{
for(int i = 0; i < node.Nodes.Count; i++)
{
listBox2.Items.Add(node.Nodes[i].Text);
TraverseTreeView(node.Nodes[i]);
}
}