See Also Example
Applies To
Combo box, list box
Description
This property is an array of long integer Not available at design time.
Usage
[form.]{ combobox|listbox}.ItemData(listindex)[ = numericexpression ]
Remarks
Use the ItemData property to associate a specific number with each item in a combo box or list box. You can then use these numbers in code to identify the items. For example, you can use an employee's identification number to identify each employee name in a list box. When you fill the list box, also fill the corresponding elements in the ItemData array with the employee numbers.
A typical use of the ItemData property is for an index into an array of data structures associated with items in a list box.
Note When you insert an item into a list with the AddItem method, an item is automatically inserted in the ItemData array as well. However, the value is not reinitialized to zero; it retains the value that was in that position before you added the item to the list. When you use the ItemData property, be sure to set its value when adding new items to a list.
Data Type
Long integer
Help:
AddItem Method
List Property
ListIndex Property
NewIndex Property
RemoveItem Method
Selected Property
TopIndex Property
Programmer's Guide:
Chapter 3, "Creating and Using Controls"
ItemData and NewIndex Properties Example
The example fills a list box with employee names and fills the ItemData array with employee numbers using NewIndex to keep the numbers synchronized with the sorted list. A label displays the name and number of an item when the user makes a selection. To try this example, paste the code into the Declarations section of a form that contains a list box and a label. Set the Sorted property for the list box to True. Then press F5 and click the list box.
Sub Form_Load ()
' Fill List1 and ItemData array with
' corresponding items in sorted order.
List1.AddItem "Judy Phelps"
List1.ItemData(List1.NewIndex) = 42310
List1.AddItem "Chien Lieu"
List1.ItemData(List1.NewIndex) = 52855
List1.AddItem "Mauro Sorrento"
List1.ItemData(List1.NewIndex) = 64932
List1.AddItem "Cynthia Bennet"
List1.ItemData(List1.NewIndex) = 39227
End Sub
Sub List1_Click ()
' Append the employee number and the employee name.
Msg = List1.ItemData(List1.ListIndex) & " "
Msg = Msg & List1.List(List1.ListIndex)
Label1.Caption = Msg
End Sub