Editable Combogadget problem

Just starting out? Need help? Post your questions and find answers here.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Editable Combogadget problem

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
infratec
Always Here
Always Here
Posts: 7588
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Editable Combogadget problem

Post by infratec »

Works here: PB 5.62 x86 on Win10 x64
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Editable Combogadget problem

Post 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!
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post by collectordave »

Windows 7(64 bit) PB 5.61
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post by collectordave »

Windows 7 x64

PB5.62 x64 also tried PB5.61 x86

Still does not work
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Editable Combogadget problem

Post by IdeasVacuum »

Weird: Win7 x64 PB5.62 x86 works fine!

EDIT: PB5.61 x86 also works fine, as does PB5.61 x64.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post by collectordave »

Just tried

Win7 x64 PB5.62 x86

Still not working
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post 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.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
deeproot
Enthusiast
Enthusiast
Posts: 284
Joined: Thu Dec 17, 2009 12:00 pm
Location: Llangadog, Wales, UK
Contact:

Re: Editable Combogadget problem

Post 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?
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: Editable Combogadget problem

Post 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.
macOS Catalina 10.15.7
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post 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?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Editable Combogadget problem

Post 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

Egypt my love
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post by collectordave »

Thanks rashad

works great now just mac and linux to go

Regards

cd
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Editable Combogadget problem

Post 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
Egypt my love
collectordave
Addict
Addict
Posts: 1310
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Editable Combogadget problem

Post 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
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply