Working with the TreeView Control

The TreeView control provides a way to display data hierarchically. The TreeView control supports properties and methods for changing the appearance of the control and events for keyboard and mouse actions.

The TreeView control uses a collections of Nodes objects to store and display data. The properties of the Node objects define the hierarchical structure of the TreeView. The Text, Image, and ExpandedImage properties of the control determine what text and icons will be displayed in the TreeView control when it is connected to an ImageList.

The TreeView events are similar to the ListView events. Both the AfterLabelEdit and the BeforeLabelEdit events are generated if, and only if, you set the LabelEdit property to 0 (tvwAutomatic) or you invoke the StartLabelEdit method. To determine which object's label is edited by a user, use the SelectedItem property. The AfterLabelEdit event is generated after a user finishes the editing operation, which occurs when the user clicks on another node and then presses the ENTER key.

Nodes can collapse or expand, generating events. There are three methods of collapsing a node: by setting the Node object's Expanded property to False; by double-clicking a Node object; and by choosing a plus/minus image when the TreeView control's Style property is set to a style that includes plus/minus images. All these methods generate the Collapse event.