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?
Printable View
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?
Errr.... What? Did you mean to ask this in a C# forum?
yeah... :)
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.