ComboBoxGadget 'Default Text' and 'Invoke Commands'

Just starting out? Need help? Post your questions and find answers here.
Peter_DevRes
User
User
Posts: 39
Joined: Tue Mar 17, 2009 6:58 pm
Location: UK

ComboBoxGadget 'Default Text' and 'Invoke Commands'

Post by Peter_DevRes »

Hi there,

I am having a problem setting the 'default text' in the control to suggest what the control is being used for. Tried SetGadgetText, but that only works if I use #PB_ComboBox_Editable, but I don't want the user to be able to edit the text, so I can use that.

Any suggestions?

Code: Select all

    ; ComboBoxGadget (#ComboBoxImport, 5, 158, 250 , 20, #PB_ComboBox_Editable)
    ComboBoxGadget (#ComboBoxImport, 5, 158, 250 , 20)
    ; AddGadgetItem (#ComboBoxImport, -1, "Please Select Importer")
    AddGadgetItem (#ComboBoxImport, -1, "Item 1")
    AddGadgetItem (#ComboBoxImport, -1, "Item 2")
    AddGadgetItem (#ComboBoxImport, -1, "Item 3")
    AddGadgetItem (#ComboBoxImport, -1, "Item 4")
    ; SetGadgetText (#ComboBoxImport, "Please Select Importer")

Furthermore, not exactly sure what the best way is to detect the selection and run a program (runprogram) from it.

Any advise would be appreciated.

Thanks & Regards,
Peter
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You can only use SetGadgetText() on a non-editable combo if the text is in the drop down list!

In such cases you're better off using SetGadgetState() anyhow.
I may look like a mule, but I'm not a complete ass.
rrpl
Enthusiast
Enthusiast
Posts: 121
Joined: Fri Apr 18, 2008 7:22 am
Location: Australia

Post by rrpl »

I usually just use the Gadget Tool Tip for this:

GadgetToolTip(#ComboBoxImport, "Please Select Importer")

not good enough?
Peter_DevRes
User
User
Posts: 39
Joined: Tue Mar 17, 2009 6:58 pm
Location: UK

Post by Peter_DevRes »

Thanks for the feedback, but that doesn't provide default text in the combo box.

There must be some way to do add generic text in to the control, so it is clear what the drop down is used for.

Pure Basic must be able to do this, it is basic functionality. The only other solution would be to have a border around it and put some text above it, but that is a little clumsey and a bit of an overkill to do this for several drop downs. Or to put the generic description as an entry and find a way to force it to viewable, but not allow it to be selected.

There must be a way to do this.

Anyone, any ideas???

Once I get this working I will write a 'Tip's and Trick's' article on the forum, so we all know how to do it.


Best Regards,
Peter.
Peter_DevRes
User
User
Posts: 39
Joined: Tue Mar 17, 2009 6:58 pm
Location: UK

Post by Peter_DevRes »

Hi,

It was the doubled 'declare' that didn't make sense to me.

AddGadgetItem(1,-1,"Select a number...")
SetGadgetText(1,"Select a number...")

I am new to Pure Basic, and didn't understand how gadget syntax is to be applied. I had tried several ways to achieve what I wanted, each time not adding and setting only adding or selecting. Hense my fustration.

Good to have this finally understood.

Best Regards,
Peter
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

I don't get what the problem is. What's wrong with the below? The user knows
they have to select a number, so what's the problem? The fact that they can
select the text in the first entry? In that case, shouldn't your app just fail to
do whatever if the user leaves it in that state? Seems like much ado about
nothing to me... <Shrugs shoulders>. Here's how I'd do it:

Code: Select all

windir$=Space(999) : GetWindowsDirectory_(windir$,999)
If Right(windir$,1)<>"\" : windir$+"\" : EndIf

If OpenWindow(0,300,300,300,100,"test",#PB_Window_SystemMenu)
  ComboBoxGadget(1,10,10,150,22)
  AddGadgetItem(1,-1,"Select an app to run...")
  SetGadgetText(1,"Select an app to run...")
  AddGadgetItem(1,-1,"Notepad")
  AddGadgetItem(1,-1,"RegEdit")
  ButtonGadget(2,170,10,50,22,"Run it!")
  SetActiveGadget(1)
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget And EventGadget()=2
      Select GetGadgetText(1)
        Case "Select an app to run..." : MessageBeep_(#MB_ICONERROR)
        Case "Notepad" : RunProgram(windir$+"notepad.exe")
        Case "RegEdit" : RunProgram(windir$+"regedit.exe")
      EndSelect
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
Note: I know I don't need windir$ to launch the apps, but I thought I'd put
it in there anyway, as an extra lesson for anyone who doesn't know it. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Peter_DevRes
User
User
Posts: 39
Joined: Tue Mar 17, 2009 6:58 pm
Location: UK

Post by Peter_DevRes »

The code above was great, thanks for taking the time to have a look.


Best Regards,
Peter
Post Reply