Syntax 2: When you know the item number
Description
Finds and highlights an item in a ListBox or RibbonComboBoxItem
when you can specify the index number of the item. You can also clear
the selection by specifying zero as the index number.
Applies to
ListBox, DropDownListBox, PictureListBox, DropDownPictureListBox,
and RibbonComboBoxItem controls
Syntax
|
1 |
listboxname.SelectItem ( itemnumber ) |
|
Argument |
Description |
|---|---|
|
listboxname |
The name of the ListBox or RibbonComboBoxItem control in |
|
itemnumber |
An integer whose value is the location (index) of the Specify 0 for itemnumber to clear the selected item. For |
Return value
Integer.
Returns the index number of the selected item. SelectItem returns
0 if itemnumber is not valid or if you specified 0 in order to clear the
selected item. It returns -1 if an error occurs. If any argument’s value
is null, SelectItem returns null.
Usage
To find an item but not select it, use the FindItem function.
MultiSelect ListBoxes
SelectItem has no effect on a ListBox or PictureListBox whose
MultiSelect property is true. Instead, use SetState to select items
without affecting the selected state of other items in the
list.
Clearing the text box of a drop-down list
To clear the text box of a DropDownListBox,
DropDownPictureListBox, or RibbonComboBoxItem that the user cannot
edit, set itemnumber to 0. Setting the control’s text to the empty
string does not work if the control’s AllowEdit property is
false.
Examples
This example highlights item number 5:
|
1 2 |
integer li_Index li_Index = lb_Actions.SelectItem(5) |
This example clears the selection from the text box of the
DropDownListBox ddlb_choices and sets li_Index to 0:
|
1 2 |
integer li_Index li_Index = ddlb_choices.SelectItem(0) |
This example highlights item 2 in the ribbon combo box:
|
1 2 3 4 5 6 7 8 |
Integer li_Return RibbonComboBoxItem lr_ComboBox li_Return = lr_ComboBox.AddItem("Item1") li_Return = lr_ComboBox.AddItem("Item2") li_Return = lr_ComboBox.SelectedIndex() li_Return = lr_ComboBox.SelectItem(2) li_Return = lr_ComboBox.SelectedIndex() |
See also