Syntax 2 When you know the item number
Description
Finds and highlights an item in a ListBox when you can specify
the index number of the item. You can also clear the selection by
specifying zero as the index number.
Controls
ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls
Syntax
1 |
<span>listboxname</span>.<span>SelectItem</span> ( <span>itemnumber</span> ) |
Argument |
Description |
---|---|
listboxname |
The name of the ListBox control in which |
itemnumber |
An integer whose value is the location Specify 0 for itemnumber to clear the |
Return Values
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.

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.

To clear the text box of a DropDownListBox or DropDownPictureListBox
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 |
integer li_Index |
1 |
li_Index = lb_Actions.<span>SelectItem</span>(5) |
This example clears the selection from the text box
of the DropDownListBox ddlb_choices and
sets li_Index to 0:
1 |
integer li_Index |
1 |
li_Index = ddlb_choices.<span>SelectItem</span>(0) |