TreeView

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.

To add items to the TreeView you would add nodes using the add method off of nodes collection. Nodes are similar to the listitems of the Listview.

This is the syntax to for the add method of the nodes collection:

object. Add(relative, relationship, key, text, image, selected image)

Example:

TreeView.Nodes.Add(, , "A", "Main Node 1", 1, 1)

***Found in the Help under Add Method (Nodes Collection)

Like the Listview, 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.

New to Visual Basic 6

In Visual Basic 6 the following functionality was added to the TreeView control:

--Full Row Select is the ability to highlight the entire row when clicking on an item.

The code to enable this is : TreeView1.FullRowSelect = True

--The user can also add checkboxes to the left of each node in the treeview control.

The code to enable this is : TreeView1.Checkboxes = True

--Hot tracking is the ability to indicate which item would be selected, with an

underline, if the user were to click with the mouse.

The code to enable this is : TreeView1.HotTracking = True

Sample Project
  1. Start a new project.
  2. Go to Project Components and add Microsoft Windows Common Controls 6.0 to your project.
  3. Add a Treeview and An ImageList to your form.
  4. Using the add method add 2 parents each with 5 children.
Bonus

Add 3 checkboxes to the sample project, one for each new VB6 functionality (fullrow select, checkboxes and hot tracking). Have the check box effect the treeview control appropriately when checked. (For example when checkboxes is selected, checkboxes appear to the left of each node, when it is not selected no checkboxes appear)


The above information was compiled from portions of the Vb5 and Vb6 Help files. The "New In VB6" and the "Bonus" sections were compiled by Buddy West. Copyright Microsoft.


[Home]   [Back to the top]


1