This documentation is archived and is not being maintained.

TreeNodeCollection::GetEnumerator Method

Returns an enumerator that can be used to iterate through a TreeNodeCollection object.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public:
virtual IEnumerator^ GetEnumerator() sealed

Return Value

Type: System.Collections::IEnumerator
An enumerator that can be used to iterate through the TreeNodeCollection.

Implements

IEnumerable::GetEnumerator()

Use the GetEnumerator method to create an enumerator that can be easily iterated through to get each item in the TreeNodeCollection. To get the item currently pointed to in the enumerator, use the IEnumerator::Current property. Use the IEnumerator::MoveNext method to move to the next item. If you need to move the enumerator back to the beginning of the collection, use the IEnumerator::Reset method.

NoteNote

After you create an enumerator or use the IEnumerator::Reset method, you must call the IEnumerator::MoveNext method. Otherwise, the item represented by the IEnumerator::Current property is undefined.

As an alternative, you can also use the CopyTo method to create an System::Array object that can be used to access the items in the collection. Another alternative is to use a foreach or For Each structure to iterate through the collection.

The following example demonstrates how to use the GetEnumerator method to create an enumerator that contains root nodes of the TreeView control.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: