From Xojo Documentation
Jump to: navigation, search

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.

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

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

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


The ComboBox height is limited to just a single size on macOS, so any changes to the Height property are ignored.

On Cocoa, 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 )


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

Dim s As String
Dim i, last As Integer
Dim d As New Date
s = "January,February,March,April,May,June,July," _
last = CountFields(s,",")
For i = 1 To last
Me.AddRow(NthField(s, ",", i))
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.


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


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

The following line changes the selected item in a ComboBox

ComboBox1.ListIndex = 3

See Also

TextField, PopupMenu controls; RectControl class.

Personal tools

Starting Out
Dig Deeper
More Help