Combobox:add(itemtext1 [, itemtext2...]) method


Add one or more items to the Combobox list.

itemtext1, itemtext2...

One or more strings representing the text of the new Combobox items.
These items can later be accessed using the Combobox.items property, as ComboItems objects.

Return value

This function returns the last added ComboItem

Example

local ui = require "ui" -- create a simple Window local win = ui.Window("Combobox:add() sample", "fixed", 320, 80) local label = ui.Label(win, "New item :", 10, 30) local entry = ui.Entry(win, "", label.x+label.width+6, label.y-4) local button = ui.Button(win, "Add item", entry.x+entry.width+6, label.y-6) local combobox = ui.Combobox(win, {}, button.x+button.width+6, label.y-4) button.enabled = false function button:onClick() -- add new item in the Combobox and select it combobox.selected = combobox:add(entry.text) entry.text = "" end -- enable button only if entry.text is not empty function entry:onChange() button.enabled = #entry.text > 0 end entry.onSelect = button.onClick win:show() -- update user interface repeat ui.update() until not win.visible