combo box selectedGadgetItem bug?

BlitzPlus Forums/BlitzPlus Programming/combo box selectedGadgetItem bug?

Idiot(Posted 2004) [#1]

window=CreateWindow( "ComboBox demo",0,0,350,200 )

combobox=CreateListBox( 0,0,128,100,window)
textfield=CreateTextField(130,0,128,24,window)
For k=0 To 9
AddGadgetItem combobox,"Item "+k
Next

SelectGadgetItem combobox,0

While WaitEvent(20)<>$803
	
		If EventSource()=combobox
			SetGadgetText(textfield,"Item selected:"+SelectedGadgetItem(combobox))
		EndIf
	
Wend

End


Ok, this is a slightly modified version of the simple_combobox.bb example in the Mak folder. You can select different items with the mouse and the value shows up in the text area. But... if you change them with the arrow keys, it doesn't get updated.

Is this a bug or am I doing something wrong?


Mr Brine(Posted 2004) [#2]
Im not one for pedantic-ness but its actualy a listbox in your demo, but yer right it looks like a bug. You'll be glad to know their is a work around. Check it Out:

; ---------------------------------------------------------


window=CreateWindow( "ComboBox demo",0,0,350,200 )

combobox=CreateListBox( 0,0,128,100,window)
textfield=CreateTextField(130,0,128,24,window)
For k=0 To 9
AddGadgetItem combobox,"Item "+k
Next

SelectGadgetItem combobox,0

HotKeyEvent 200, 0, $401, 0, 0, 0, -1, combobox ; up
HotKeyEvent 208, 0, $401, 0, 0, 0, 1, combobox ; down


While WaitEvent(20)<>$803

If EventSource()=combobox

If(SelectedGadgetItem(combobox) + EventZ() < 0)

SelectGadgetItem combobox, 0

Else If(SelectedGadgetItem(combobox) + EventZ() => CountGadgetItems(combobox))

SelectGadgetItem combobox, CountGadgetItems(combobox) - 1

Else

SelectGadgetItem combobox, SelectedGadgetItem(combobox) + EventZ()

End If

SetGadgetText(textfield,"Item selected:"+SelectedGadgetItem(combobox))

EndIf

Wend

End

; ----------------------------------------------------------

Hope this helps!

Mr Brine


pantsonhead.com(Posted 2004) [#3]
Thanks! That's a handy work around - just what I needed.

It's still a bit flakey when you hold the key down until it starts repeating though :(