Functions for inserting items
There are several functions for adding items to a TreeView
control, as shown in the following table.
|
This function |
Adds an item here |
|---|---|
|
InsertItem |
After a sibling item for the specified If no siblings exist, you must use one of |
|
InsertItemFirst |
First child of the parent item. |
|
InsertItemLast |
Last child of the parent item. |
|
InsertItemSort |
As a child of the parent item in alphabetic order, |
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 2 3 4 5 6 7 |
long ll_tvi, ll_tvparent ll_tvi = tv_list.FindItem(CurrentTreeItem!, 0) ll_tvparent = tv_list.FindItem(ParentTreeItem!, & ll_tvi) tv_list.InsertItem(ll_tvparent, ll_tvi, & "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 the following table.
|
Property |
Value |
|---|---|
|
Label |
The text that is displayed for the |
|
PictureIndex |
A value from the regular picture |
|
SelectedPictureIndex |
A value from the regular picture list, specifying a |
|
StatePictureIndex |
A value from the State picture list. The picture is |
|
Children |
Must be TRUE if you want double-clicking to trigger |
|
Data |
An optional value of any datatype that you want to |
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 2 3 4 5 6 7 8 9 10 |
treeviewitem tvi long h_item = 0, h_parent = 0 h_parent = tv_1.FindItem(CurrentTreeItem!, 0) tvi.Label = "Choral" tvi.PictureIndex = 1 tvi.SelectedPictureIndex = 2 tvi.Children = true tvi.StatePictureIndex = 0 h_item = tv_1.InsertItemSort(h_parent, tvi) |
For more information about inserting items into a TreeView
control, see the section called “InsertItem” in PowerScript Reference.