ComboBox

From Xojo Documentation

Class (inherits from PopupMenu)

A ComboBox is a combination of a TextField and a PopupMenu. The user can type in the field or click to select an item from a list.

Events
Change DropObject MouseExit
Close GotFocus MouseMove
ConstructContextualMenu KeyDown MouseUp
ContextualMenuAction KeyUp MouseWheel
DragEnter LostFocus Open
DragExit MouseDown TextChanged
DragOver MouseEnter


Properties
Active fa-lock-32.png ListCount fa-lock-32.png TabIndex
AutoComplete ListIndex TabStop
AutoDeactivate LockBottom Text
Bold LockLeft TextFont
DataField LockRight TextSize
DataSource LockTop Top
Enabled MouseCursor Transparent
Handle fa-lock-32.png MouseX fa-lock-32.png TrueWindow fa-lock-32.png
Height MouseY fa-lock-32.png Underline
HelpTag Name UseFocusRing
Index fa-lock-32.png PanelIndex Visible
InitialValue fa-lock-32.png Parent Width
Italic Scope fa-lock-32.png Window fa-lock-32.png
Left SelLength
List fa-lock-32.png SelStart


Methods
AcceptFileDrop Close RefreshRect
AcceptPictureDrop DeleteAllRows RemoveRow
AcceptRawDataDrop DrawInto RowTag
AcceptTextDrop InsertRow SetFocus
AddRow Invalidate
AddRows Refresh

Notes

macOS

On macOs, the ComboBox height is limited to just a single size, so any changes to the Height property are ignored.

Additionally, the maximum number of visible rows in the dropdown is 15. You can adjust this number using this declare, passing in the ComboBox's handle for controlHandle:

Declare Sub setNumberOfVisibleItems Lib "AppKit" Selector "setNumberOfVisibleItems:" (controlHandle As Integer, count As Integer)
setNumberOfVisibleItems(MyComboBox.Handle, 30)

Windows

On Windows, the ComboBox height is controlled by the font size, so any changes you make to the Height property are ignored.

Examples

This code in the Open event handler populates a ComboBox and sets the initial value to the current month:

Dim s As String
Dim last As Integer
Dim d As New Date
s = "January,February,March,April,May,June,July," _
+ "August,September,October,November,December"
last = CountFields(s, ",")
For i As Integer = 1 To last
Me.AddRow(NthField(s, ",", i))
Next
Me.ListIndex = d.Month - 1

The value of the ListIndex property contains the index of the selected item, but it does not indicate whether the user has entered text into the ComboBox. Examine the Text property to get the current menu selection or the text entered by the user. For example, the following line in the TextChanged event handler displays either the currently selected menu item or the text typed into the ComboBox.

Label1.Text = Me.Text

This example adds an item to a ComboBox in its Open event handler.

Me.AddRow("October")

This example opens a new window when an item is chosen.

Sub Change()
Dim w As ListEditorWindow
If ComboBox1.Text = "Edit List..." Then
w = New ListEditorWindow
End If
End Sub

The following line changes the selected item in a ComboBox

ComboBox1.ListIndex = 3

See Also

TextField, PopupMenu controls; RectControl class.