Inserting items at the root level
The very first item you insert does not have any sibling for
specifying a relative position, so you cannot use the
InsertItem function — you must use InsertItemFirst or InsertItemLast.
For an item inserted at the root level, you specify 0 as its
parent.
This sample code is in a user event triggered from the Open event
of the window containing the TreeView. It assumes two instance variable
arrays:
-
A string array called item_label that contains labels for all
the items that will be inserted at the root level (here composer
names) -
An integer array that has values for the Data property (the
century for each composer); the century value is for user-defined
sorting:1234567891011121314int ctlong h_item = 0treeviewitem tviFOR ct = 1 TO UpperBound(item_label)tvi.Label = item_label[ct]tvi.Data = item_data[ct]tvi.PictureIndex = 1tvi.SelectedPictureIndex = 2tvi.Children = TRUEtvi.StatePictureIndex = 0tvi.DropHighlighted = TRUEh_item = tv_1.InsertItemSort(0, tvi)NEXT
After inserting all the items, this code scrolls the TreeView back
to the top and makes the first item current:
|
1 2 3 4 |
// Scroll back to top h_item = tv_1.FindItem(RootTreeItem!, 0) tv_1.SetFirstVisible(h_item) tv_1.SelectItem(h_item) |