See Also Example
Combo box, directory list box, drive list box , file list box , list box .
Determines the index Not available at design time. of the currently selected item in the control.
[form.]control.ListIndex[ = index ]
The ListIndex property settings are:
-1 (Default for combo box, directory list box, and drive list box) Indicates no item is currently selected. For a combo box, indicates the user has entered new text into the text box portion of the combo box. For a directory list box, indicates the index of the current path. For a drive list box, indicates the index of the current drive when the control is created at run time.
n (Default for file list box and list box) A number indicating the index of the currently selected item.
The expression List(List1.ListIndex) returns the string for the currently selected item.
The first item in the list is ListIndex 0, and ListCount is always one more than the largest ListIndex value.
Chapter 3, "Creating and Using Controls"
ListIndex Property Example
The example displays the names of three players in a list box and the corresponding salary of the selected player in a label. To try this example, paste the code into the Declarations section of a form that contains a combo box and a label. Then press F5 and choose a name from the combo box.
' General declarations
Dim Player(0 To 2) ' Dimension two arrays.
Dim Salary(0 To 2)
Sub Form_Load ()
Dim I ' Declare variable.
AutoSize = True
Player(0) = "Miggey McMoo" ' Enter data into arrays.
Player(1) = "Alf Hinshaw"
Player(2) = "Woofer Dean"
Salary(0) = "$234,500"
Salary(1) = "$158,900"
Salary(2) = "$1,030,500"
For I = 0 To 2 ' Add names to list.
Combo1.ListIndex = 0 ' Display first item in list.
Sub Combo1_Click ()
' Display corresponding salary for name.
Label1.Caption = Salary(Combo1.ListIndex)