Assembly: System.Web (in system.web.dll)
The TreeNodeCollection class is used to store and manage a collection of TreeNode objects in the TreeView control. The TreeView control uses the TreeNodeCollection class in two of its properties. It stores its root nodes in the Nodes property and its selected nodes in the CheckedNodes property. The TreeNodeCollection collection is also used for the ChildNodes property to store child nodes (if any).
The TreeNodeCollection class supports several ways to access the items in the collection:
Use the Item indexer to retrieve a TreeNode object directly at a specific zero-based index.
Use the GetEnumerator method to create an enumerator that can be used to iterate through the collection.
Use foreach (C#) or For Each (Visual Basic) to iterate through the collection.
You can programmatically manage the TreeNodeCollection by adding and removing TreeNode objects. To add nodes to the collection, use the Add or AddAt method. To remove nodes from the collection, use the Remove, RemoveAt, or Clear method.
When the TreeView control is bound to a data source, the Nodes and ChildNodes collections are automatically populated each time binding occurs. Any changes to the collections between bindings will be lost. To retain these changes, either update the data source or manually rebuild the collection each time you bind.
The TreeNodeCollection contains properties and methods that allow you to retrieve information about the collection itself. To find out how many items are in the collection, use the Count property. If you want to determine whether the collection contains a certain TreeNode object, use the Contains method. To get the index of a TreeNode object in the collection, use the IndexOf method.
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.