How does ComboBoxGadget editable work?

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

How does ComboBoxGadget editable work?

Post by WilliamL »

I ran the example in the on-line documentation and get the combobox with the ability to change the text, in the selection box, but changing the text doesn't seem to have any effect. Is this what editable means? How does this work?

Code: Select all

If OpenWindow(0, 0, 0, 270, 140, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ComboBoxGadget(0, 10, 10, 250, 21, #PB_ComboBox_Editable)
      AddGadgetItem(0, -1, "1ComboBox editable...")
      AddGadgetItem(0, -1, "2ComboBox editable...")
      AddGadgetItem(0, -1, "3ComboBox editable...")
      
    SetGadgetState(0,1)    ; set (beginning with 0) the second item is active one

    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You can get the text from the edit control with GetGadgetText(). If you want to put that text into one of the items, use SetGadgetItemText().

Generally the use of the editable combobox is to provide the user with a number of choices or let him enter his own. Its not supposed to automatically update the list of choices.
quidquid Latine dictum sit altum videtur
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Ok, he can enter his own... I can't see how this works. I can see how the combobox gives a choice but, I can't see how the programs recognizes that a field is to be added or edited? I suppose I could check the selected choice for the text being changed, for editing, but that doesn't cover the 'add' possibility.

I think I must be missing the point.
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Well, what exactly do you want to do with it ?

Check out the Find dialog of the IDE for example:
When you open the dialog, the combobox list is filled with the previously searched words. The user can then either select one of these or enter his own. When the user hits the search button, the current text is stored, so it can be added to the previous searches list the next time.

Maybe its better to think of the editable combobox not as an editable list of items, but rather as a StringGadget that can offer a set of predefined texts as a choice. This is the way in which it is usually used.

If you want a live editable list instead, you have to add some means of triggering the "add" action (like a button). You'd probably want a "remove" button too then.
quidquid Latine dictum sit altum videtur
WilliamL
Addict
Addict
Posts: 1255
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Post by WilliamL »

Yes, I see, like a string field that can be filled by the choices but that the entered text is always acted upon. Now I see that this is different from the 'non editable' which is always a choice action. That's two very different actions from the same gadget.

I think I understand. Now, I got to use it in one of my programs. :D
MacBook Pro-M1 (2021), Tahoe 26.1, PB 6.30b2
Post Reply