SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftMask/OCX 7.0 - Masked Edit Control
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftPrintPreview/DLL 2.0 - Print Preview Control (discontinued)
SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftDirectory 3.5 - File/Folder Control (discontinued)
SftMask/OCX 7.0 - Masked Edit Control
SftOptions 1.0 - Registry/INI Control (discontinued)
SftPrintPreview/OCX 1.0 - Print Preview Control (discontinued)
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftTabs/NET 6.0 - Tab Control (discontinued)
SftTree/NET 2.0 - Tree Control
Items in a tree control are managed as a linear list or array of items. All API functions that access a particular item require the item index. This is a zero-based number describing the item position. The first item in the tree control has item index 0, the second is item 1, etc. Consequently, if an item is inserted at the top of the list, all previously added items now receive a new item index.
Index 0 | First Item |
Index 1 | Second Item |
Index 2 | Third Item |
Index 3 | Fourth Item |
Once a new item is added, the tree control looks like this:
Index 0 | New Item |
Index 1 | First Item |
Index 2 | Second Item |
Index 3 | Third Item |
Index 4 | Fourth Item |
An item index describes the position in the tree control, so it is subject to change if items are added or removed.
In some cases it may be easier to work with a constant value describing an item no matter where it is located in the list of items. This is possible using item IDs. Once an item has been added to the tree control, its ID can be retrieved using GetItemID. The returned item ID does not change, even if other items are added or removed. Given an item ID, the current item index can be found using GetItemIndex.
Saving the item ID is most useful for top level parent items. Top level items usually show item categories. Since adding or removing child items of other parent items changes a top level parent's index, it is easier to work with item IDs. When a top level parent item is added, save the item ID retrieved using GetItemID. Later, regardless of how many other items have been added or removed, a call to GetItemIndex with the saved item ID will return the current item index.
SFTTREE_ID savedID; int index; index = m_Tree1.AddString("Category 1"); savedID = m_Tree1.GetItemID(index); . . . other items added/inserted and removed // retrieve the item index for "Category 1" index = m_Tree1.GetItemIndex(savedID); . . . processing for Category 1