Combobox.items read/write property iterable
Provides access to the list of the Combobox items.
Reading this property returns a table that contains a list of ComboItem. This table can be indexed by item index or by item text. The item position starts from 1. Using a wrong index or an invalid text will return a nil value.
Setting this property will change the entire list of items in the combobox. It expects a table that contains a list of strings (each string will be an item in the Combobox list)
Example
local ui = require "ui"
-- create a simple Window
local win = ui.Window("Combobox.items sample", 306, 80)
local label = ui.Label(win, "Enter an item index : ", 10, 30)
local entry = ui.Entry(win, "1", label.x+label.width+6, label.y-4, 22, 22)
local combobox = ui.Combobox(win, { "LuaRT", "is", "fun"}, entry.x+entry.width+6, label.y-4)
-- disable the combobox
combobox.enabled = false
-- Event fired when user press RETURN in the Entry field
function entry:onSelect()
local item = combobox.items[entry.text] or false
if item then
combobox.selected = item
else
ui.error(entry.text.." is not a valid index")
end
end
entry:onSelect()
win:show()
-- update user interface
repeat
ui.update()
until not win.visible