Managing TreeView items
An item in a TreeView is a TreeViewItem structure. The preceding
section described how to set the item’s properties in the
structure and then insert it into the TreeView.
This code declares a TreeViewItem structure and sets several
properties:
|
1 |
TreeViewItem tvi_defined<br> <br>tvi_defined.Label = "Symphony No. 3 Eroica"<br>tvi_defined.StatePictureIndex = 0<br>tvi_defined.PictureIndex = 3<br>tvi_defined.SelectedPictureIndex = 4<br>tvi_defined.OverlayPictureIndex = 0<br>tvi_defined.Children = TRUE |
For information about Picture properties,
see “Managing TreeView pictures”.
When you insert an item, the inserting function returns a
handle to that item. The TreeViewItem structure is copied to the
TreeView control, and you no longer have access to the item’s
properties:
|
1 |
itemhandle = This.InsertItemLast(parenthandle, &<br>   tvi_defined) |
Procedure for items: get, change, and set
If you want to change the properties of an item in the TreeView,
you:
-
Get the
item, which assigns it to a TreeViewItem structure. -
Make the changes, by setting
TreeViewItem properties. -
Set the item, which copies
it back into the TreeView.
When you work with items that have been inserted in the TreeView,
you work with item handles. Most TreeView events pass one or two
handles as arguments. The handles identify the items the user is
interacting with.
This code for the Clicked event uses the handle of the clicked
item to copy it into a TreeViewItem structure whose property values
you can change:
|
1 |
treeviewitem tvi<br>This.GetItem(handle, tvi)<br>tvi.OverlayPictureIndex = 1<br>This.SetItem(handle, tvi) |
Important
Remember to call the SetItem function after
you change an item’s property value. Otherwise, nothing
happens in the TreeView.
Items and the hierarchy
You can use item handles with the FindItem function
to navigate the TreeView and uncover its structure. The item’s
properties tell you what its level is, but not which item is its
parent. The FindItem function does:
|
1 |
long h_parent<br>h_parent = This.FindItem(ParentTreeItem!, handle) |
You can use FindItem to find the children
of an item or to navigate through visible items regardless of level.
For more information, see the FindItem function
in the PowerScript Reference.
Enabling TreeView functionality in scripts
By setting TreeView properties, you can enable or disable
user actions like deleting or renaming items without writing any
scripts. You can also enable these actions by calling functions.
You can:
-
Delete items
-
Rename items
-
Move items using drag and drop
-
Sort items