Pictures for items

There are several ways to use pictures in a TreeView. You associate a picture in one of the picture lists with an item by setting one of the item’s picture properties, described in Table 8-6.

Table 8-6: TreeView picture properties

Property

Purpose

PictureIndex

The primary picture associated with the item is displayed just to the left of the item’s label.

StatePictureIndex

A state picture is displayed to the left of the regular picture. The item moves to the right to make room for the state picture. If the Checkboxes property is TRUE, the state picture is replaced by a pair of check boxes.

Because a state picture takes up room, items without state pictures will not align with items that have pictures. So that all items have a state picture and stay aligned, you could use a blank state picture for items that do not have a state to be displayed.

A use for state pictures might be to display a check mark beside items the user has chosen.

OverlayPictureIndex

An overlay picture is displayed on top of an item’s regular picture.

You set up the overlay picture list in a script by designating a picture in the regular picture list for the overlay picture list.

An overlay picture is the same size as a regular picture, but it often uses a small portion of the image space so that it only partially covers the regular picture. A typical use of overlay pictures is the arrow marking shortcut items in the Windows Explorer.

SelectedPictureIndex

A picture from the regular picture list that is displayed instead of the regular picture when the item is the current item. When the user selects another item, the first item gets its regular picture and the new item displays its selected picture.

If you do not want a different picture when an item is current, set SelectedPictureIndex to the same value as PictureIndex.

How to set pictures You can change the pictures for all items at a particular level with the SetLevelPictures function, or you can set the picture properties for an individual item.

If you do not want pictures Your TreeView does not have to use pictures for items. If an item’s picture indexes are 0, no pictures are displayed. However, the TreeView always leaves room for the regular picture. You can set the PictureWidth property to 0 to eliminate that space:

tv_2.DeletePictures()
tv_2.PictureWidth = 0