Functions for inserting items
There are several functions for adding items to a TreeView
control, as shown in Table 8-2.
|
This |
Adds an item here |
|---|---|
|
InsertItem |
After a sibling item for the specified If no siblings exist, you must use one of the other insertion functions. |
|
InsertItemFirst |
First child of the parent item. |
|
InsertItemLast |
Last child of the parent item. |
|
InsertItemSort |
As a child of the parent item in alphabetic |
For all the InsertItem functions, the SortType
property can also affect the position of the added item.
There are two ways to supply information about the item you
add, depending on the item properties that need to be set.
Method 1: specifying the label and picture index
only
You can add an item by supplying the picture index and label.
All the other properties of the item will have default values. You
can set additional properties later as needed, using the item’s
handle.
Example
This example inserts a new item after the currently selected
item on the same level as that item. First it gets the handles of
the currently selected item and its parent, and then it inserts
an item labeled Hindemith after the currently
selected item. The item’s picture index is 2:
|
1 |
long ll_tvi, ll_tvparent<br> <br>ll_tvi = tv_list.FindItem(CurrentTreeItem!, 0)<br>ll_tvparent = tv_list.FindItem(ParentTreeItem!, &<br>   ll_tvi)<br>tv_list.<span>InsertItem</span>(ll_tvparent, ll_tvi, &<br>   "Hindemith", 2) |
Method 2: setting item properties in a TreeViewItem structure
You can add items by supplying a TreeViewItem structure with
properties set to specific values. The only required property is
a label. Properties you might set are shown in Table 8-3.
|
Property |
Value |
|---|---|
|
Label |
The text that is displayed for the item. |
|
PictureIndex |
A value from the regular picture list. |
|
SelectedPictureIndex |
A value from the regular picture list, |
|
StatePictureIndex |
A value from the State picture list. |
|
Children |
Must be TRUE if you |
|
Data |
An optional value of any datatype that |
Example
This example sets all these properties in a TreeViewItem structure before
adding the item to the TreeView control. The item is inserted as
a child of the current item:
|
1 |
treeviewitem tvi<br>long h_item = 0, h_parent = 0<br> <br>h_parent = tv_1.FindItem(CurrentTreeItem!, 0)<br>tvi.Label = "Choral"<br>tvi.PictureIndex = 1<br>tvi.SelectedPictureIndex = 2<br>tvi.Children = true<br>tvi.StatePictureIndex = 0<br>h_item = tv_1.InsertItemSort(h_parent, tvi) |
For more information about inserting items
into a TreeView control, see the PowerScript Reference.