ItemData Property

See Also33H7N13                 ExampleF4IZ3M>Low

Applies To

Combo box1YZXFF6, list boxG11UCK.


This property is an array of long integer1DDU1E5 values with the same number of items as a control's ListBKCX6E property.  Not available at design time.


[form.]{ combobox|listbox}.ItemData(listindex)[ = numericexpression ]


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 AddItem2BIX3OB 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 integer103F6YL

See Also


AddItem Method2BIX3OB

List PropertyBKCX6E

ListIndex Property4K7KHR

NewIndex PropertyIOGOXY

RemoveItem MethodM867OS

Selected PropertyKC8D7W

TopIndex Property2EAX0Z


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