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 ComboBox in Reference Guide for details on all its events, properties and methods.

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

Events

Change

Called when the selected item in the popup menu has changed.

TextChanged

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

Properties

List

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.

ListCount As Integer

An Integer containing the number of rows in the menu.

ListIndex As Integer

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

Text As String

Contains the text of the currently selected row.

Methods

AddRow, AddRows

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).

DeletaAllRows

Removes all rows from the menu.

InsertRow

Takes as parameters the row and name of item to insert into the menu.

RemoveRow

Takes as parameters the number of the row to remove.

RowTag

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:

Dim names() As String = Array("Fred", "Jane", "Bill", "Betty")
ComboBox1.AddRows(names)

See Also

ComboBox class; UserGuide:Desktop Popup Menu topic