felix1432
September 7th, 2010, 11:52 AM
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?
GCDEF
September 7th, 2010, 12:30 PM
Errr.... What? Did you mean to ask this in a C# forum?
felix1432
September 7th, 2010, 12:50 PM
yeah... :)
Eri523
September 7th, 2010, 09:56 PM
No, the TreeView class doesn't have a subnodes member. But it has a Nodes property that is of type TreeNodeCollection ^ (http://msdn.microsoft.com/en-us/library/system.windows.forms.treenodecollection.aspx). 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() (http://msdn.microsoft.com/en-us/library/system.windows.forms.treenodecollection.getenumerator.aspx). 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.