CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2010
    Posts
    83

    for each & treeview-nodes

    Hi,

    I have a treeView control, to which i add treenodes at runtime.
    How can i implement a for each loop as in

    for each (TreeNode^ a in treeVie1->subnode....){
    ....
    }

    if "subnode" doesnt exist when compiling the program?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: for each & treeview-nodes

    Errr.... What? Did you mean to ask this in a C# forum?

  3. #3
    Join Date
    May 2010
    Posts
    83

    Re: for each & treeview-nodes

    yeah...

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: for each & treeview-nodes

    No, the TreeView class doesn't have a subnodes member. But it has a Nodes property that is of type TreeNodeCollection ^. Unfortunately, you can't iterate over the nodes therein using a plain for each. Instead, you have to use the enumerator returned by its method GetEnumerator(). Of course, you'll have to do that in a recursive manner to get every single node contained in the TreeView.

    I haven't used that myself yet, so I can't give you much more that these pointers to the MSDN docs for now. I hope it will help you, though.

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

Featured