ComboBox
From Xojo Documentation
Supported Platforms Project Types: Desktop Platforms: macOS, Windows, Linux |
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.
Properties | |||||||||||||||||||||||||||||||||||||||||||||
|
Methods | |||||||||||||||
|
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:
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 Open event handler populates a ComboBox and sets the initial value to the current month:
Var last As Integer
Var 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 SelectedRowIndex property contains the index of the selected item, but it does not indicate whether the user has entered a value into the ComboBox. 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.
This code adds an item to a ComboBox in its Open event handler.
This code opens a new window when an item is chosen.
Var w As ListEditorWindow
If ComboBox1.Value = "Edit List..." Then
w = New ListEditorWindow
End If
End Sub
The following code changes the selected item in a ComboBox