Class: TreeView
Properties | Events | Methods | Index of Classes
Provides a control that displays a hierarchical list of items, such as the headings in a document, the entries in an index, or the files and folders on a disk
Hierarchy
cObject > cUIObject > DfBaseObject > DfBaseWindow > DfBaseUIWindow > DfBaseControl > DfBaseList > DfBaseListbox > List > AbstractTreeView > TreeView
Show full hierarchy and direct subclasses
Library: Windows Application Class Library
Package: DfTreeVw.pkg
Description
The TreeView class is used to provide a control that displays a hierarchical list of items, such as the headings in a document, the entries in an index, or the files and folders on a disk. Each item consists of a label and an image, and each item can have a list of subitems associated with it. By clicking an item, users can expand and collapse the associated list of subitems.
Sample
Use DfAllEnt.pkg
Use DfTreeVw.pkg
Enum_List
Define tiDF
Define tiBin
Define tiLib
Define tiExamples
Define tiWines
Define tiContact
End_Enum_List
Object oPanel is a Panel
Set Size to 140 240
Set Location to 20 20
Set Label to "TreeView Sample"
Object oTreeView is a TreeView
Set Size to 100 100
Set Location to 10 10
// create an image list for the images
Object oImageList is a cImageList32
Set piMaxImages to 3
Procedure OnCreate // add the images
Integer iImage
Get AddTransparentImage 'Open16.bmp' clFuchsia to iImage
Get AddTransparentImage 'Select16.bmp' clFuchsia to iImage
Get AddTransparentImage 'New16.bmp' clFuchsia to iImage
End_Procedure
End_Object
// Now assign the ImageList to the TreeView
Set ImageListObject to (oImageList(Self))
Procedure OnCreateTree
Handle hItemRoot hItemChild hItemExamples
Get AddTreeItem "DataFlex" 0 tiDataFlex 0 1 to hItemRoot
Get AddTreeItem "Bin" hItemRoot tiBin 2 1 to hItemChild
Get AddTreeItem "Lib" hItemRoot tiLib 2 1 to hItemChild
Get AddTreeItem "Examples" hItemRoot tiExamples 0 1 to hItemExamples
Get AddTreeItem "Wines" hItemExamples tiWines 2 1 to hItemChild
Get AddTreeItem "Contact" hItemExamples tiContact 2 1 to hItemChild
End_Procedure
End_Object
End_Object
Start_UI
This example creates a cImageList32 instance that is used to store the images used by this object. This object adds six items during its OnCreateTree event. Each item stores a user-defined value (from the enumerated list of symbols) that can be used to identify each item.
Note
This class is a wrapper for the Windows Tree View common control.
Its interface is somewhat different from other DataFlex classes. Rather than dealing with an indexed list of items (as you would in, say, the List class), this class identifies each item with a handle. This handle is a unique identifier that Windows supplies. Whenever you address an item, you must refer to it by its handle. In the example above, the returned handle of a parent item is used when creating child items to identify their parent.
Because of the "handle-based" nature of this class, some of properties that would normally be defined as item properties will be treated as handle properties. Instead of passing an item number as the first parameter, a handle is used. Examples of this are ItemData, ItemLabel, and ItemImage.
You add items to the control using the AddTreeItem function and you can also call this function inside the OnCreateTree.
To display bitmap images alongside each item, you need to associate an ImageList object, which you add images into. Each item of this object can have two images: a regular image displayed alongside items and an image that is displayed instead, whenever the item is currently focused (the current item).
Use the OnItemClick event to get a notification when the user clicks an item, or OnItemChanged to know whenever the current item changes.
The tree control items supports line (piLineColor), background (piBackColor) and text colors (piTextColor), info tips (pbEnableInfoTips), and more.
Individual tree items support images (ItemImage, ItemSelectedImage) and labels (ItemLabel), check boxes (ItemCheckBox), bold text (ItemBold) and more.
Important: Note that items in this object are created when the control is paged (activated) and destroyed when the object is unpaged (deactivated). See OnCreateTree for more information on this.