class ComboBox : WinControl
The ComboBox class represents a combo box control.
A combo box allows the user to select one entry from a list of items. It can be created with createComboBox.
Inheritance
| Class
|
Inherits From
|
Description
|
| ComboBox
|
WinControl
|
Represents a combo box control.
|
| WinControl
|
Control
|
Base class for controls that can receive focus and contain child controls.
|
| Control
|
Component
|
Base class for visible GUI controls.
|
| Component
|
Object
|
Base class for components.
|
| Object
|
None
|
Base class for Lua-exposed objects.
|
Creation
function createComboBox(owner) : ComboBox
Creates a ComboBox object that belongs to the given owner.
The owner can be any object inherited from WinControl.
Function Parameters
| Parameter
|
Type
|
Description
|
| owner
|
WinControl
|
The owner of the combo box.
|
Returns
ComboBox — The created combo box object.
Properties
| Property
|
Type
|
Description
|
| Items
|
Strings
|
A Strings-derived object containing all items in the list.
|
| ItemIndex
|
Integer
|
The selected item index. -1 means no item is selected.
|
| Canvas
|
Canvas
|
The canvas object used to render on the combo box.
|
Methods
| Method
|
Return Type
|
Description
|
| clear()
|
void
|
Removes all items from the combo box.
|
| getItems()
|
Strings
|
Returns the Strings object containing the combo box items.
|
| setItems(items)
|
void
|
Sets the combo box items.
|
| getItemIndex()
|
Integer
|
Returns the selected item index.
|
| setItemIndex(index)
|
void
|
Sets the selected item index.
|
| getCanvas()
|
Canvas
|
Returns the canvas object used to render on the combo box.
|
| getExtraWidth()
|
Integer
|
Returns the number of pixels not part of the text area of the combo box, such as borders and the drop-down button.
|
Examples
Create a ComboBox
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Left = 10
5 comboBox.Top = 10
6 comboBox.Width = 180
7
8 form.show()
Add items to a ComboBox
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Items.add("First item")
5 comboBox.Items.add("Second item")
6 comboBox.Items.add("Third item")
7
8 comboBox.ItemIndex = 0
9
10 form.show()
Read the selected item index
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Items.add("Low")
5 comboBox.Items.add("Medium")
6 comboBox.Items.add("High")
7
8 local index = comboBox.ItemIndex
9
10 print("Selected index: " .. tostring(index))
11
12 form.show()
Set the selected item index
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Items.add("Small")
5 comboBox.Items.add("Normal")
6 comboBox.Items.add("Large")
7 comboBox.ItemIndex = 1
8
9 form.show()
Use getItems
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 local items = comboBox.getItems()
5
6 items.add("Red")
7 items.add("Green")
8 items.add("Blue")
9
10 comboBox.ItemIndex = 0
11
12 form.show()
Use getItemIndex and setItemIndex
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Items.add("Option A")
5 comboBox.Items.add("Option B")
6 comboBox.Items.add("Option C")
7
8 comboBox.setItemIndex(2)
9
10 print("Selected index: " .. tostring(comboBox.getItemIndex()))
11
12 form.show()
Clear all items
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Items.add("Temporary A")
5 comboBox.Items.add("Temporary B")
6 comboBox.Items.add("Temporary C")
7
8 comboBox.clear()
9
10 form.show()
Get the combo box canvas
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 local canvas = comboBox.getCanvas()
5
6 print(canvas.ClassName)
7
8 form.show()
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 local extraWidth = comboBox.getExtraWidth()
5
6 print("Extra width: " .. tostring(extraWidth))
7
8 form.show()
React to a changed selection
1 local form = createForm(false)
2 local comboBox = createComboBox(form)
3
4 comboBox.Items.add("Beginner")
5 comboBox.Items.add("Advanced")
6 comboBox.Items.add("Expert")
7
8 comboBox.OnChange = function(sender)
9 print("Selected index: " .. tostring(sender.ItemIndex))
10 end
11
12 comboBox.ItemIndex = 0
13
14 form.show()
Core Lua documentation entry points