Visual Basic: Windows Controls
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.
After creating a TreeView control, you can add, remove, arrange, and otherwise manipulate 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.
*Distribution Note* The TreeView control is part of a group of ActiveX controls that are found in the MSCOMCTL.OCX file. To use the TreeView control in your application, you must add the MSCOMCTL.OCX file to the project. When distributing your application, install the MSCOMCTL.OCX file in the user's Microsoft Windows System or System32 directory.