Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

ListIndex, ListItemId

These properties provide two different ways to identify the currently selected item in a list or combo box.

Usage

oObject.ListIndex = nSelectItem
nSelectItem = oObject.ListIndex
oObject.ListItemId = nSelectItem
nSelectItem = oObject.ListItemId

Each item in a list or combo box gets a unique ID number (ItemId) that it keeps no matter how the list changes. In addition, each item can be accessed based on its visible position (or Index) in the list. (For a complete explanation of the two ways of looking at a list, see AddItem.)

ListItemId returns the unique ID number for the currently selected item in the list or combo. ListIndex returns the visible position of the currently selected item. The ItemId of an entry never changes; its Index changes as items are added and removed, if the Sorted property changes, and when items are moved around with the mover bars.

ListItemId can be used as an index into the ListItem, ItemIdData and SelectedId array properties. ListIndex can be used with the List, ItemData and Selected array properties. (List and ListItem contain the actual data shown in the list or combo box. ItemData and ItemIdData are auxiliary arrays you can use to store additional data related to the list items. Selected and SelectedId indicate which items are currently highlighted.)

Example

* Find the contents of the selected item
cCurItem = cboMyCombo.List[ ListIndex ]
* or
cCurItem = cboMyCombo.ListItem[ ListItemId ]

* Remove the currently selected item
lstMyList.RemoveItem[ ListIndex ]
* or
lstMyList.RemoveListItem[ ListItemId ]

See Also

AddItem, AddListItem, ComboBox, IndexToItemId, ItemData, ItemIdData, ItemIdToIndex, List Property, ListBox, ListItem, RowSourceType, Selected, SelectedId