SelectItem

Finds and highlights an item in a ListBox, DropDownListBox, RibbonComboBoxItem, or TreeView control.

To select an item

Use

In a ListBox control when you know the text of the item, but not its position

Syntax 1

In a ListBox or RibbonComboBoxItem control when you know the position of the item in the control's list, or to clear the current selection

Syntax 2

In a TreeView control

Syntax 3


Syntax 1: When you know the text of an item

Description

Finds and highlights an item in a ListBox when you can specify some or all of the text of the item.

Applies to

ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls

Syntax

listboxname.SelectItem ( item, index )

Argument

Description

listboxname

The name of the ListBox control in which you want to select a line

item

A string whose value is the starting text of the item you want to select

index

The number of the item after which you want to begin the search


Return value

Integer.

Returns the index number of the selected item. If no match is found, SelectItem returns 0; it returns -1 if an error occurs. If any argument's value is null, SelectItem returns null.

Usage

SelectItem begins searching for the desired item after the item identified by index. To match, the item must start with the specified text; however, the text in the item can be longer than the specified text.

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 edit box of a drop-down list

To clear the edit box of a DropDownListBox or DropDownPictureListBox that the user cannot edit, use Syntax 2 of SelectItem.

Examples

If item 5 in lb_Actions is Delete Files, this example starts searching after item 2, finds and highlights Delete Files, and sets li_Index to 5:

integer li_Index
li_Index = lb_Actions.SelectItem("Delete Files", 2)

If item 4 in lb_Actions is Select Objects, this example starts searching after item 2, finds and highlights Select Objects, and sets li_Index to 4:

integer li_Index
li_Index = lb_Actions.SelectItem("Sel", 2)

See also

AddItem

DeleteItem

FindItem

InsertItem

SetState

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

listboxname.SelectItem ( itemnumber )

Argument

Description

listboxname

The name of the ListBox or RibbonComboBoxItem control in which you want to select an item

itemnumber

An integer whose value is the location (index) of the item in the ListBox or the ListBox portion of the drop-down list.

Specify 0 for itemnumber to clear the selected item. For a ListBox or PictureListBox, 0 removes highlighting from the selected item. For a DropDownListBox, DropDownPictureListBox or RibbonComboBoxItem, 0 clears the text box.


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:

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:

integer li_Index
li_Index = ddlb_choices.SelectItem(0)

This example highlights item 2 in the ribbon combo box:

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

AddItem

DeleteItem

FindItem

InsertItem

SetState

Syntax 3: For TreeView controls

Description

Selects a specified item.

Applies to

TreeView controls

Syntax

treeviewname.SelectItem ( itemhandle )

Argument

Description

treeviewname

The name of the TreeView control in which you want to select an item

itemhandle

The handle of the specified item


Return value

Integer.

Returns 1 if it succeeds and -1 if an error occurs.

Usage

Use the FindItem function to get handles for items at specific positions in the TreeView control.

Examples

This example selects the parent of the current TreeView item:

long ll_tvi, ll_tvparent
int li_tvret
ll_tvi = tv_list.FindItem(CurrentTreeItem! , 0)
ll_tvparent = tv_list.FindItem(ParentTreeItem! , &
      ll_tvi)
li_tvret = tv_list.SelectItem(ll_tvparent)

See also

FindItem