Set ComboBox to "unselected?"
BlitzMax Forums/BlitzMax Programming/Set ComboBox to "unselected?"
| ||
| Hi! I have a combobox with 4 items and just want to set it to -1 state = unselected, so that the combobox displays an empty field then.
Strict
Local window:TGadget
Local combobox:TGadget
window=CreateWindow("My Window",30,20,200,200)
combobox=CreateComboBox(4,4,120,22,window)
AddGadgetItem combobox,"Item 1"
AddGadgetItem combobox,"Item 2"
AddGadgetItem combobox,"Item 3"
AddGadgetItem combobox,"Item 4"
While WaitEvent()
Select EventID()
Case EVENT_GADGETACTION
Print "eventdata="+EventData()
Case EVENT_WINDOWCLOSE
End
End Select
Wend
How to do that? |
| ||
| Maybe* you can use deselectgadgetitem. Alternatively, create a dummy GadgetItem (addgadgetitem, combobox,"") and select it when you want to reset. |
| ||
| Great, thanks Tony. As usual I have not seen this command in the docs.. :(
Strict
Local window:TGadget
Local button:TGadget
Local combobox:TGadget
window=CreateWindow("My Window",30,20,200,200)
button=CreateButton("Deselect",10,82,70,24,window,BUTTON_OK)
combobox=CreateComboBox(4,4,120,22,window)
AddGadgetItem combobox,"Item 1"
AddGadgetItem combobox,"Item 2"
AddGadgetItem combobox,"Item 3",True
AddGadgetItem combobox,"Item 4"
While WaitEvent()
Select EventID()
Case EVENT_GADGETACTION
Print "eventdata="+EventData()
Case EVENT_WINDOWCLOSE
End
End Select
Select EventSource()
Case Button
DeselectGadgetItem (combobox, SelectedGadgetItem(combobox))
End Select
Wend
|
| ||
-1 is actually understood as "all gadget items". It should probably have a constant, ALL_ITEMS or something. In something with multiple selectable items,DeselectGadgetItem gadget,-1 would be the right way to make sure everything is deselected, while SelectGadgetItem gadget,-1 would select ALL of them (instead of only selecting the final item, which is what it appears to do on gadgets that can only have one item selected at a time). You can test this by doing it on a toolbar - all the buttons will become selected. |
| ||
| Thanks! Again, it would be nice to have an update for the docs! :/ |
| ||
| SelectedGadgetItem still returns -1 to mean "no item", so if you want to save the selection-state of an item gadget to a variable, and then re-apply it later on using SelectGadgetItem, you'll have to make a special case for -1. |