Paths and File Names
Observed online
Resources for the beginner
Graphics Drawing Rules
beginner's guide to API and DLL
Drawing IN MEMORY
Radiobuttons via API
NumbWord
Working with Comboboxes
This demo is the result of a thread on the Liberty Basic group that dealt with reseting the combobox back to a blank value after the list has been pulled down once. Usually once a value list has been viewed the list will display one of the value on the value list, and unless blank is one of the possible values (we did not want it to be) then it is difficult to get back to blank.
This demo shows one of several ways to accomplish this task. This version is a bit more robust in that it also handles the situation where the user supplies their own value - you see unless disabled by an API call the combobox will accept user input much the same way a textbox will as I discuss in the message snippet below:
The one thing that can be a "gotcha" when using the combobox is
that the USER can type a value into the
combobox. If you do not do something to handle that condition then your program
will appear to leave the user in
the lurch if they were to assume their value was good but you appeared to
ignore it. This happens when you simply
retrieved the index or item from the combobox and presume the user had typed
nothing into the control and thend displayed your indexed item and not the
user's input.
That is why I recommended testing the combobox with the command CONTENTS? so that you can determine whether the use actually entered an alternate value. This demo will check for user input and then ADD it to the value list if it is unique:
'Code for LB3 'test combo reset to null - Brad Moore Dim item$(15) item$(1) = "Black" item$(2) = "Buttonface" item$(3) = "White" ttlItems = 3 ForegroundColor$ = "Black" BackgroundColor$ = "Buttonface" TexteditorColor$ = "White" TextboxColor$ = "White" ComboboxColor$ = "White" ListboxColor$ = "White" [WindowSetup] NoMainWin WindowWidth = 193 : WindowHeight = 219 UpperLeftX = Int((DisplayWidth-WindowWidth)/2) UpperLeftY = Int((DisplayHeight-WindowHeight)/2) [ControlSetup] Button #main.reset, "Force Reset",[reset],UL, 35, 60, 105, 25 Button #main.quit, "Quit",[quit],UL, 35, 140, 105, 25 Button #main.info, "Get Info",[info],UL, 35, 100, 105, 25 Combobox #main.combo1,item$(,[combo1.click], 20, 20, 142, 300 Open "Test Combo" For Dialog As #main Print #main, "trapclose [quit]" Print #main, "font ms_sans_serif 10" [loop] Wait [quit] Close #main End [reset] Print #main.combo1, "! " GoTo [loop] [info] print #main.combo1, "contents? text$" Print #main.combo1, "selection? selected$" Print #main.combo1, "selectionindex? index" if text$ <> selected$ then if text$ > " " then 'the user has entered an all new value '(maybe we will add it to the list) gosub [addToItems] else index = 0 selected$ = "" end if end if 'report what we got... Notice "Combobox Info" + Chr$(13) + "Index selected: " + Str$(index) + _ " Value Selected: " + selected$ GoTo [loop] [combo1.click] Print #main.combo1, "selection? selected$" GoTo [loop] [addToItems] if ttlItems = 15 then Notice "Error" + Chr$(13) + _ "Sorry can not add more items to list box" return end if 'keep track of total items ttlItems = ttlItems + 1 item$(ttlItems) = text$ print #main.combo1, "reload" print #main.combo1, "selectindex "; ttlItems 'Now get the values again Print #main.combo1, "selection? selected$" Print #main.combo1, "selectionindex? index"