Results 1 to 2 of 2

Thread: Looping all items in a Treeview control

  1. #1

    Thread Starter
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159

    Looping all items in a Treeview control

    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

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I'm not at my dev box right now, but here is a sample recursive routine that would traverse the treeview:

    Code:
    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]);
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width