There are several functions for adding items to a TreeView control, as shown in Table 6-5.
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.
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:
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)
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 6-6.
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:
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)
Copyright © 2004. Sybase Inc. All rights reserved. |
![]() |