Obtains the number of the selected item in a ListBox, ListView, or RibbonComboBoxItem control.

Applies to

ListBox, ListView, and RibbonComboBoxItem controls


listcontrolname.SelectedIndex ( )




The name of the ListBox, ListView, or RibbonComboBoxItem control in which you want to locate the selected item

Return value


Returns the index of the selected item in listcontrolname. If more than one item is selected, SelectedIndex returns the index of the first selected item. If there are no selected items or an error occurs, SelectedIndex returns -1. If listcontrolname is null, SelectedIndex returns null.


SelectedIndex and SelectedItem are meant for lists that allow a single selection only (when the MultiSelect property for the control is false).

When the MultiSelect property is true, SelectedIndex gets the index of the first selected item only. Use the State function, instead of SelectedIndex, to check each item in the list and find out if it is selected. Use the Text function to get the text of any item in the list.


If item 5 in lb_actions is selected, then this example sets li_Index to 5:

integer li_Index
li_Index = lb_actions.SelectedIndex()

These statements open the window w_emp if item 5 in lb_actions is selected:

integer li_X
li_X = lb_actions.SelectedIndex()
If li_X = 5 then Open(w_emp)

These statements return the index of the selected item in the RibbonBar ComboBox:

Integer li_Return
RibbonComboBoxItem lr_ComboBox

li_Return = lr_ComboBox.AddItem("Item1")
li_Return = lr_ComboBox.AddItem("Item2")
li_Return = lr_ComboBox.SelectedIndex()

See also