Represents a node of a TreeView.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The Nodes collection holds all the child objects assigned to the current . You can add, remove, or clone a ; when doing so, all child tree nodes are added, removed, or cloned. Each can contain a collection of other objects. This can make it difficult to determine where you are in the TreeView when iterating through the collection. To determine your location in a tree structure, use the FullPath property. The FullPath string can be parsed using the PathSeparator string value to determine where a label begins and ends.
The label is set by setting the Text property explicitly. The alternative is to create the tree node using one of the TreeNode constructors that has a string parameter that represents the Text property. The label is displayed next to the image, if one is displayed.
To display images next to the tree nodes, assign an ImageList to the ImageList property of the parent TreeView control and assign an Image by referencing its index value in the ImageList property. Set the ImageIndex property to the index value of the Image you want to display when the is in an unselected state. Likewise, set the SelectedImageIndex property to the index value of the Image you want to display when the is selected.
Selecting specific tree nodes and iterating through the Nodes collection can be achieved by using the following property values: FirstNode, LastNode, NextNode, PrevNode, NextVisibleNode, PrevVisibleNode. Assign the returned by one of aforementioned properties to the TreeView.SelectedNode property to select that tree node in the TreeView control.
Tree nodes can be expanded to display the next level of child tree nodes. The user can expand the by pressing the plus (+) button next to the , if one is displayed, or you can expand the by calling the Expand method. To expand all child tree node levels in the Nodes collection, call the ExpandAll method. You can collapse the child level by calling the Collapse method, or the user can press the minus (-) button next to the , if one is displayed. You can also call the Toggle method to alternate the between the expanded and collapsed states.
Tree nodes can optionally display a check box. To display the check boxes, set the CheckBoxes property of the TreeView to true. The Checked property is set to true for tree nodes that are in a checked state.Notes to Inheritors:
The following code example displays customer information in a TreeView control. The root tree nodes display customer names, and the child tree nodes display the order numbers assigned to each customer. In this example, 1,000 customers are displayed with 15 orders each. The repainting of the TreeView is suppressed by using the BeginUpdate and EndUpdate methods, and a wait Cursor is displayed while the TreeView creates and paints the objects. This example requires that you have a Customer object that can hold a collection of Order objects. It also requires that you have created an instance of a TreeView control on a Form.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.