Page 1 of 2
Editable Combogadget problem
Posted: Sat Feb 24, 2018 10:27 am
by collectordave
Probably just me but I want to get the text in the displayed portion of an editable combobox gadget.
When I select text from the list no problem. If the text is set by the programme getgadgettext returns the last selected text. Code below to demonstrate. Click the right button which should give you the text no bother click left button once then click right button text not returned?
Am I missing something here?
Code: Select all
Global Window_0
Global Combo_0,Button_0,Button_1
Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu)
Combo_0 = ComboBoxGadget(#PB_Any, 120, 40, 200, 30, #PB_ComboBox_Editable)
Button_0 = ButtonGadget(#PB_Any, 240, 140, 100, 20, "")
Button_1 = ButtonGadget(#PB_Any, 140, 140, 100, 20, "Set")
;Load Combo List
For iLoop = 1 To 10
AddGadgetItem(Combo_0,-1,"Item " + Str(iLoop))
Next
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
Debug GetGadgetText(Combo_0)
Case Button_1
SetGadgetText(Combo_0,"test text")
EndSelect
EndSelect
ForEver
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 10:35 am
by infratec
Works here: PB 5.62 x86 on Win10 x64
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 10:41 am
by Shardik
Works also here: MacOS 10.6.8 'Snow Leopard' with PB 5.62 x86
You should always state your OS, OS version and PB version!
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 10:57 am
by collectordave
Windows 7(64 bit) PB 5.61
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 11:05 am
by collectordave
Windows 7 x64
PB5.62 x64 also tried PB5.61 x86
Still does not work
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 11:15 am
by IdeasVacuum
Weird: Win7 x64 PB5.62 x86 works fine!
EDIT: PB5.61 x86 also works fine, as does PB5.61 x64.
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 11:23 am
by collectordave
Just tried
Win7 x64 PB5.62 x86
Still not working
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 11:43 am
by collectordave
Maybe a little more info
1. Start programme.
2. Select item from drop down say "Item 2"
3. Click right hand button. "Item 2" appears in debug window.
4. Click Left hand button. "test text" appears in combo box.
5 Click right hand button. "Item 2" appears in debug window not "test text"
Lots of other combinations appear to give correct results such as editing the text after being set or setting before selecting from dropdown. GetgadgetText seems unreliable.
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 1:15 pm
by deeproot
@collectordave - Yup, I'm getting the same effect as you, when following the sequence above. Tested on Win7 x64, PB 5.62 x64.
Strange! - I use editable ComboBoxGadgets quite a lot and never noticed the issue. However, I don't suppose I ever read back the text directly after setting it, because at that point I already know what it is!
I may be getting this wrong, but the GetGadgetText appears to be always reading the value from the "current element" unless the text in the box has been changed. You may notice that the SetGadgetText does not fire a Change event (I added a test to your code).
It's also interesting that the Help says "GetGadgetText(): Get the (text) content of the current element." Entering text in the box does not change the current element, so strictly speaking you could say that it works as documented. But once a Change has been detected then it does return the text in the box. Bit inconsistent maybe?
I've no idea if that could be considered a bug or just a behaviour, or even a documentation thing?
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 1:48 pm
by Wolfram
Here is also something strange.
If I press "set" the first time I get an empty combobx field. So I have to press it twice to get "test text" inside the combo gadget.
But I always get the text from the combo box in the debugger.
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 3:19 pm
by collectordave
Looking a bit deeper the question should really be is there any reliable way to get the displayed text from an editable combo box that works in all cases?
noticed that no change event fired. Aldo noticed that when the text set by set text matches text in the list the same effect happens.
Need this as it is part of a database project where the list is populated from a database which can be different for each user. So they can select from the list or if the entry they want is not there they can enter text in the editable portion which when moving onor saving the entered text is added to the database and the combo repopulated ready for the next selection when it will be in the list.
If the text cannot be read reliably is there any alternative?
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 3:49 pm
by RASHAD
No problem it is as per the PB Document
But as long as you are windows user adapt the next to your needs
Code: Select all
Global Window_0
Global Combo_0,Button_0,Button_1
Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu)
Combo_0 = ComboBoxGadget(#PB_Any, 120, 40, 200, 30, #PB_ComboBox_Editable)
hEdit = FindWindowEx_(GadgetID(Combo_0), #Null, "Edit", #Null)
Button_0 = ButtonGadget(#PB_Any, 240, 140, 100, 20, "")
Button_1 = ButtonGadget(#PB_Any, 140, 140, 100, 20, "Set")
;Load Combo List
For iLoop = 1 To 10
AddGadgetItem(Combo_0,-1,"Item " + Str(iLoop))
Next
buffer$ = Space(#MAX_PATH)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case Button_0
SendMessage_(hEdit,#WM_GETTEXT,#MAX_PATH,@buffer$)
Debug Buffer$
Case Button_1
SetGadgetText(Combo_0,"test text")
EndSelect
EndSelect
ForEver
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 4:00 pm
by collectordave
Thanks rashad
works great now just mac and linux to go
Regards
cd
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 4:34 pm
by RASHAD
Try the next for Windows ,Linux & Mac
Code: Select all
Global Window_0
Global Combo_0,Button_0,Button_1
Window_0 = OpenWindow(#PB_Any, 0, 0, 600, 400, "", #PB_Window_SystemMenu)
Combo_0 = ComboBoxGadget(#PB_Any, 120, 40, 200, 30, #PB_ComboBox_Editable)
Button_0 = ButtonGadget(#PB_Any, 240, 140, 100, 20, "")
Button_1 = ButtonGadget(#PB_Any, 140, 140, 100, 20, "Set")
;Load Combo List
For iLoop = 1 To 10
AddGadgetItem(Combo_0,-1,"Item " + Str(iLoop))
Next
Buffer$ = Space(#MAX_PATH)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case Combo_0
Buffer$ = GetGadgetText(Combo_0)
Case Button_0
Debug Buffer$
;
Case Button_1
Buffer$ = "test text"
SetGadgetText(Combo_0,Buffer$)
EndSelect
EndSelect
ForEver
Re: Editable Combogadget problem
Posted: Sat Feb 24, 2018 5:03 pm
by collectordave
Definately works with windows
will check Mac and Linux when I can
Thanks again Rashad
Maybe put in a feature request?
Regards
cd