TreeView Control

A TreeView control displays a hierarchical list of Node objects, each of which consists of a label and an optional bitmap. A TreeView is typically used to display the headings in a document, the entries in an index, the files and directories on a disk, or any other kind of information that might usefully be displayed as a hierarchy.

Syntax

TreeView

The properties, methods and events of the TreeView control are described in the following table.

Properties Methods Events
FontBold GetVisibleCount AfterLabelEdit
FontItalic StartLabelEdit BeforeLabelEdit
FontName Collapse
FontSize Expand
FontStrikeThrough NodeClick
FontUnderline
HideSelection
ImageList
Indentation
LabelEdit
LineStyle
Nodes
PathSeparator
SelectedItem
Sorted (TreeView)
Style (TreeView)

Remarks

After creating a TreeView control, you can add, manipulate, and remove Node objects by setting properties and invoking methods. You can programmatically expand and collapse Node objects to display or hide all child nodes. Three events, the Collapse, Expand, and NodeClick event, also provide programming functionality.

You can navigate through a tree in code by retrieving a reference to Node objects using Root, Parent, Child, FirstSibling, Next, Previous, and LastSibling properties. Users can navigate through a tree using the keyboard as well. UP ARROW and DOWN ARROW keys cycle downward through all expanded Node objects. Node objects are selected from left to right, and top to bottom. At the bottom of a tree, the selection jumps back to the top of the tree, scrolling the window if necessary. RIGHT ARROW and LEFT ARROW keys also tab through expanded Node objects, but if the RIGHT ARROW key is pressed while an unexpanded Node is selected, the Node expands; a second press will move the selection to the next Node. Conversely, pressing the LEFT ARROW key while an expanded Node has the focus collapses the Node. If a user presses an ANSI key, the focus will jump to the nearest Node that begins with that letter. Subsequent pressings of the key will cause the selection to cycle downward through all expanded nodes that begin with that letter.

Several styles are available which alter the appearance of the control. Node objects can appear in one of eight combinations of text, bitmaps, lines, and plus/minus signs.

The TreeView control uses the ImageList control, specified by the ImageList property, to store the bitmaps and icons that are displayed in Node objects. A TreeView control can use only one ImageList at a time. This means that every item in the TreeView control will have an equal-sized image next to it when the TreeView control's Style property is set to a style which displays images.