When setting the style property from "icons" to "text" all previously loaded icons are preserved.
Combobox.style read/write property
Get or set the current style, a string value, that specifies the Combobox appearance :
- "text" : Combobox will display only text items (default).
- "icons" : Combobox will display text items with their icons, using ComboItem:loadicon().
Example
local ui = require "ui"
-- create a simple Window
local win = ui.Window("Combobox.style sample", "fixed", 400, 240)
local label = ui.Label(win, "DoubleClick on an application :", 10, 30)
local combo = ui.Combobox(win, {}, label.x+label.width+6, label.y-4)
local checkicons = ui.Checkbox(win, "Show icons", combo.x+combo.width+12, label.y)
local applications = {
Notepad = "c:\\Windows\\notepad.exe",
Console = 'c:\\Windows\\System32\\cmd.exe'
}
for app, path in pairs(applications) do
combo:add(app):loadicon(path)
end
function combo:onDoubleClick(item)
sys.cmd("start "..applications[item.text])
end
function checkicons:onClick()
combo.style = self.checked and "icons" or "text"
win:status("combo style : "..combo.style:capitalize())
end
win:show()
-- update user interface
repeat
ui.update()
until not win.visible