[MAXGUI] Combobox with default text?

BlitzMax Forums/BlitzMax Beginners Area/[MAXGUI] Combobox with default text?

Grisu(Posted 2006) [#1]
Hi!

I was wondering if it is possible to giva a combobox a default text, such as "Select your option in here".

The text is not a Gagdetitem itself. So the user cannot select this entry in the drop-down list!

Grisu


SebHoll(Posted 2006) [#2]
The only way I could do it was to set the COMBOBOX_EDITABLE style and then using SetGadgetText$() as in the below example:
Global wndMain:TGadget = CreateWindow("Test",400,400,400,300,0,15)
	Global gadCombo:TGadget = CreateComboBox(5, 5, 200, 20, wndMain, COMBOBOX_EDITABLE)
	Global gadButton:TGadget = CreateButton("OK",210,5,40,20,wndMain)

' Adding example items to the combobox

For Local a:Byte = 0 To 20

	AddGadgetItem(gadCombo,"Item " + a)

Next

'Setting default text

SetGadgetText(gadCombo, "Please Select an Option...")

'Main Program Loop

Repeat

	Select WaitEvent()
	
		Case EVENT_WINDOWCLOSE;End
		
	End Select

Forever
Is that any good?


Seb

P.S. The problem with that is that the user can write anything into the box unless you write a validation routine yourself.

Update: I attempted to write for you a sample validation routine but it wouldn't work as I can't find a cross-platform way to retreive what the user has typed into an editable combo box. TextFieldText$() doesn't appear to update itself when a user types something in. :-) Anyone else have this problem, I have BlitzMax 1.20 running on Windows XP with latest SyncMods...


Grisu(Posted 2006) [#3]
Thanks for your help.

That is (without the edit thiggy) the exact behavior I would like to see.

Get the event with Eventhooks maybe? - Don't know how though.


SebHoll(Posted 2006) [#4]
A bit more information for you... If you call SelectedGadgetItem() with the default text in the box, it returns -1. I tried using the InsertGadgetItem() with an index of -1 to see if we could set the text in a different way however it says that the "index is out of range" with Debug Enabled and without Debug it says "Unhandled Memory Exception" if I remember correctly.

If EventHooks are needed then I won't be able to help, as I'm pretty useless with them.


Seb