DesktopComboBox

From Xojo Documentation

Class (inherits from DesktopPopupMenu)


New in 2021r3

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
Closing FocusLost MouseExit
ConstructContextualMenu FocusReceived MouseMove
ContextualMenuItemSelected KeyDown MouseUp
DragEnter KeyUp MouseWheel
DragExit MouseDown Opening
DragOver MouseDrag SelectionChanged
DropObject MouseEnter TextChanged
Properties
Active fa-lock-32.png InitialValue fa-lock-32.png Scope fa-lock-32.png
AllowAutoComplete Italic SelectedRowIndex
AllowAutoDeactivate LastAddedRowIndex fa-lock-32.png SelectedRowValue fa-lock-32.png
AllowFocusRing LastRowIndex fa-lock-32.png SelectionLength
AllowTabStop Left SelectionStart
Bold LockBottom TabIndex
Enabled LockLeft Text
FontName LockRight Tooltip
FontSize LockTop Top
FontUnit MouseCursor Transparent
Handle fa-lock-32.png Name fa-lock-32.png Underline
Height PanelIndex Visible
Hint Parent Width
Index fa-lock-32.png RowCount fa-lock-32.png Window fa-lock-32.png
Methods
AcceptFileDrop AddRowAt RowTagAt
AcceptPictureDrop Close RowValueAt
AcceptRawDataDrop DrawInto SelectRowWithTag
AcceptTextDrop Refresh SelectRowWithValue
AddAllRows RemoveAllRows SetFocus
AddRow RemoveRowAt

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.

Sample Code

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

Var s As String
Var last As Integer
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
Var d As DateTime = DateTime.Now
Var interval As New DateInterval(0, 1, 0)
d = d - interval
Me.ListIndex = d

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

Label1.Text = Me.Text

This code adds an item to a DesktopComboBox in its Opening event handler.

Me.AddRow("October")

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

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

The following code changes the selected item in a DesktopComboBox

ComboBox1.SelectedRowIndex = 3

See Also

DesktopTextField, DesktopPopupMenu controls