See Also Example
Applies To
Combo box, directory list box
Description
Determines the index Not available at design time.
Usage
[form.]control.ListIndex[ = index ]
Setting
The ListIndex property settings are:
Setting Description
-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.
Remarks
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.
Data Type
Integer
Help:
AddItem Method
Drive Property
List Property
ListCount Property
Path Property
RemoveItem Method
Programmer's Guide:
Chapter 3, "Creating and Using Controls"
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.AddItem Player(I)
Next I
Combo1.ListIndex = 0 ' Display first item in list.
End Sub
Sub Combo1_Click ()
' Display corresponding salary for name.
Label1.Caption = Salary(Combo1.ListIndex)
End Sub