HOWTO: Gain Access to Items in the ListBox ObjectID: Q147846
|
You can gain access to an item in a list box or combo box by referencing its position in the list (index) or its unique identification number (itemid). This article describes how the index method differs from the itemid method and gives the properties and methods related to each method.
Although all of this information also applies to lists with multiple
columns, the examples in this article use one-dimensional lists only.
Following are some general and property definitions. For a more complete
definition of these properties, please see the Help menu.
General Definition
-------------------------------------------------------------------------
Item an element of a list.
Index a unique number assigned by you or by the system to an item.
Itemid a unique number used to reference an item in a list.
Property Definition
----------------------------------------------------------------------
List an array used to gain access to items in index order.
ListItem an array used to gain access to items in itemid order.
ListIndex the index of the selected item in a list.
ListItemId the itemid of the selected item in a list.
ListCount the number of items in a list.
NewIndex the index of the item most recently added to the list.
NewItemId the itemid of the item most recently added to the list.
Sorted whether or not the items in a list are sorted alphabetically.
MultiSelect whether or not a user can select multiple items.
MoverBars allows movement of items in the list.
ItemData uses an index to reference an internal array to store
auxiliary data for an item.
ItemIdData uses an itemid to reference an internal array to store
auxiliary data for an item.
The resulting list would be as follows.thisform.List1.AddItem('A') adds 'A' to the list thisform.List1.AddItem('B',3) adds 'B' to the list at index 3
Item Index ItemId
A 1 1
Z 2 2
C 3 3
Use the following code to add 'b' to the list with an itemid of 14:thisform.List1.AddListItem('a')
The resulting list would be as follows.thisform.List1.AddListItem('b',14)
Item Index ItemId
A 1 1
B 2 14
thisform.List1.RemoveItem(2) removes the second item in a list.
thisform.List1.RemoveListItem(342)
thisform.List1.AddItem('b') thisform.List1.ItemData(thisform.List1.NewIndex) = 1253
If the MultiSelect property is false, the ListIndex and the ListItemId properties return the selected item.FOR I=1 TO thisform.List1.ListCount IF thisform.List1.Selected(I) =MESSAGEBOX("Item: "+ALLTRIM(thisform.List1.List(I))+ ; " is selected.") ENDIF NEXT
Additional query words:
Keywords : kbcode kbOOP kbVFp300 kbVFp500 kbVFp600
Version :
Platform :
Issue type : kbhowto
Last Reviewed: August 3, 1999