Page 1 of 1

Drop-down boxes (without edit field)

Posted: Mon Jun 13, 2005 5:48 pm
by Matt
I know the handle of a dropdown box without an edit field in a window. How would I be able to change the text of the currently displayed item?

- Matt

Posted: Thu Jun 16, 2005 2:00 pm
by Sparkie
I'm assuming you're dealing with an external window/combobox and unable to use PB's native SetGadgetItemText.

Simply replace hCombo with the handle to a ComboBox of your chioce. ;)

Code: Select all

If OpenWindow(0, 0, 0, 270, 140,  "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
  hCombo = ComboBoxGadget(0, 10, 10, 250, 100) 
  ButtonGadget(1, 10, 120, 250, 20, "Change current item text") 
  For i = 0 To 4 
    AddGadgetItem(0, -1, "ComboBox item " + Str(i)) 
  Next i 
  SetGadgetState(0, 2) 
  Repeat 
    Event = WaitWindowEvent() 
    If Event = #PB_Event_Gadget And EventGadget() = 1 
      ; --> Get the current selection in ComboBox 
      currentSelection = SendMessage_(hCombo, #CB_GETCURSEL, 0, 0) 
      ; --> Create new text 
      newText$ = "New text for item " + Str(currentSelection) 
      ; --> Delete the item at current selection 
      SendMessage_(hCombo, #CB_DELETESTRING, currentSelection, 0) 
      ; --> Insert the new item at current selection 
      SendMessage_(hCombo, #CB_INSERTSTRING, currentSelection, @newText$) 
      ; --> Select the new item 
      SendMessage_(hCombo, #CB_SETCURSEL, currentSelection, 0) 
    EndIf 
  Until Event = #PB_Event_CloseWindow 
EndIf 
***Edited to update code for PB 4.xx

Thanks

Posted: Sat Jun 18, 2005 2:42 am
by Matt
Thank you. This works perfect!

Posted: Sat Jun 18, 2005 2:49 am
by Sparkie
You're welcome Matt. :)