Set ComboBox to "unselected?"

BlitzMax Forums/BlitzMax Programming/Set ComboBox to "unselected?"

Grisu(Posted 2006) [#1]
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?


tonyg(Posted 2006) [#2]
Maybe* you can use deselectgadgetitem.
Alternatively, create a dummy GadgetItem (addgadgetitem, combobox,"") and select it when you want to reset.


Grisu(Posted 2006) [#3]
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



taxlerendiosk(Posted 2006) [#4]
-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.


Grisu(Posted 2006) [#5]
Thanks!

Again, it would be nice to have an update for the docs! :/


taxlerendiosk(Posted 2006) [#6]
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.