UserGuide

Desktop Combo Box

From Xojo Documentation

Combo Box Library Icon

The Combo Box control works like a combination of a Text Field and a Popup Menu. The user can either enter text in the Combo Box or choose an item from the attached Popup Menu. A menu selection can be modified after it is selected. Unlike a real Text Field, you cannot use a mask to filter data entry or operate it as a Password Field.

Combo Box Example

Refer to DesktopComboBox in Reference Guide for details on all its events, properties and methods.

Below is a list of common events, properties and methods.

Events

SelectionChanged - Called when the selected item in the menu has changed.

TextChanged - Called when the Text was changed, either by typing or through code (by setting the Text property).

Properties

RowValueAt - This property takes one parameter, an index of the row. It returns the text of the item in the menu specified by the index parameter. If the index does not exist, then an OutOfBoundsException is raised.

RowCount As Integer - An Integer containing the number of rows in the menu.

SelectedRowIndex As Integer - An Integer used to get or set the currently selected row in the menu.

SelectedRowValue As String - Contains the text of the currently selected row.

Methods

AddRow, AddAllRows - Takes as a parameter a string or an array of strings to add a row or rows to the menu.

AddSeparator - Adds a separator line (only on Mac).

RemoveAllRows - Removes all rows from the menu.

AddRowAt - Adds a row at the index position and using the text passed.

RemoveRowAt - Takes as parameters the number of the row to remove.

RowTagAt - Takes as a parameter the number of the row to which to assign the tag. The tag can be any value or class (variant).

Handling Focus

ComboBoxes on any platform display the focus by highlighting the selected item and showing a blinking insertion point. On Mac, a ComboBox with the focus also has a focus ring. When a ComboBox has the focus, you can scroll through the list of choices with the up and down arrow keys and select an item by pressing the Return key. Of course, you can also edit or replace the selected item.

Usage

You can use an array to populate the ComboBox:

Var names() As String = Array("Fred", "Jane", "Bill", "Betty")
ComboBox1.AddAllRows(names)

See Also

DesktopComboBox class; UserGuide:Desktop Popup Menu topic