TreeNodeCollection::GetEnumerator Method ()
.NET Framework (current version)
Returns an enumerator that can be used to iterate through the tree node collection.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Return Value
Type: System.Collections::IEnumerator^An IEnumerator that represents the tree node collection.
Implements
IEnumerable::GetEnumerator()The following code example determines if a specified TreeNode is within a TreeNodeCollection, and then enumerates the collection. This example requires that you have a Form with a TreeView that has a TreeNodeCollection that contains a TreeNode named myTreeNode2.
void EnumerateTreeNodes() { TreeNodeCollection^ myNodeCollection = myTreeView->Nodes; // Check for a node in the collection. if ( myNodeCollection->Contains( myTreeNode2 ) ) { myLabel->Text = myLabel->Text + "Node2 is at index: " + myNodeCollection->IndexOf( myTreeNode2 ); } myLabel->Text = myLabel->Text + "\n\nElements of the TreeNodeCollection:\n"; // Create an enumerator for the collection. IEnumerator^ myEnumerator = myNodeCollection->GetEnumerator(); while ( myEnumerator->MoveNext() ) { myLabel->Text = myLabel->Text + (dynamic_cast<TreeNode^>(myEnumerator->Current))->Text + "\n"; } }
.NET Framework
Available since 1.1
Available since 1.1
Show: