Combobox question

Just starting out? Need help? Post your questions and find answers here.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Combobox question

Post by karu »

Hi,

How i can open and close editable comboBox width code. How in my code i can open menu without pressing the muosebutton?

Raimo

Code: Select all

    OpenWindow(0, 200, 100, 300, 100 , "combo", #PB_Window_SystemMenu |#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    ComboBoxGadget(1, 10, 30, 280, 21,#PB_ComboBox_Editable )
    For a = 1 To 5
      AddGadgetItem(1, -1,"item " + Str(a))
    Next
   
    Repeat

      Event = WindowEvent()
     
        If EventType() = #PB_EventType_Change And EventGadget() = 1
          AddGadgetItem(1, -1, GetGadgetText(1))
        EndIf
             
    
      If Event = 0
        Delay(1)
      EndIf
        
    Until Event = #PB_Event_CloseWindow 
    End
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Combobox question

Post by luis »

On Windows, #CB_SHOWDROPDOWN

Code: Select all


  OpenWindow(0, 200, 100, 300, 100 , "combo", #PB_Window_SystemMenu |#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
    ComboBoxGadget(1, 10, 30, 280, 21,#PB_ComboBox_Editable )
    For a = 1 To 5
      AddGadgetItem(1, -1,"item " + Str(a))
    Next
    

    ButtonGadget(2,5,5,100,20," OPEN IT ")
    
    Repeat

      Event = WindowEvent()
     
        If EventType() = #PB_EventType_Change And EventGadget() = 1
          AddGadgetItem(1, -1, GetGadgetText(1))
        EndIf
        
        If EventGadget() = 2
            flag = 1 ; to open, 0 to close it
            SendMessage_(GadgetID(1),#CB_SHOWDROPDOWN,flag,0) 
        EndIf             
   
        If Event = 0
            Delay(1)
        EndIf
       
    Until Event = #PB_Event_CloseWindow
    End
"Have you tried turning it off and on again ?"
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: Combobox question

Post by karu »

Big thanks :)
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Combobox question

Post by TI-994A »

This is a modification of a code which I wrote 12 years ago on VB6, which splits the ComboBox into its component elements, and subclasses only the embedded editor control. Seems that PureBasic's ComboBoxGadget is built the same way:

Code: Select all

;==========================================================================
;
; Subclassing the ComboBox Gadget to intercept the [ENTER] key by TI-994A
;
; The ComboBox class is a combination of an editor control and a listview
; control. The handle to the editor component, which is the first child
; window in the class, is obtained by using the FindWindowEx API function.
; With that, the editor control can be subclassed to trap keyboard events.
;
;==========================================================================

Enumeration
  #MainWindow
  #ComboBox
  #ComboBox2
  #TextGadget
  #TextGadget2
EndEnumeration
      
Procedure ComboEditorProc(hWnd, uMsg, wParam, lParam)
  Shared sysProc
  Define.l result
  If uMsg = #WM_CHAR And wparam = #VK_RETURN
    If Not SendMessage_(GadgetID(#ComboBox),#CB_GETDROPPEDSTATE, 0, 0)
      SendMessage_(GadgetID(#ComboBox),#CB_SHOWDROPDOWN, 1, 0) 
      result = 0
    Else
      result = CallWindowProc_(sysProc, hWnd, uMsg, wParam, lParam)
    EndIf  
  Else
    result = CallWindowProc_(sysProc, hWnd, uMsg, wParam, lParam)
  EndIf   
  ProcedureReturn result
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 500, 200, "Subclassed ComboBox", wFlags)
ComboBoxGadget(#ComboBox, 25, 40, 200, 22, #PB_ComboBox_Editable)
ComboBoxGadget(#ComboBox2, 275, 40, 200, 22, #PB_ComboBox_Editable)
TextGadget(#TextGadget, 25, 20, 200, 22, "Keyboard Activated ComboBox")
TextGadget(#TextGadget2, 275, 20, 200, 22, "Standard ComboBox")

Restore scientists
For readData = 1 To 8
  Read.s names$
  AddGadgetItem(#ComboBox, -1, names$)
  AddGadgetItem(#ComboBox2, 0, names$)
Next readData

SetActiveGadget(#ComboBox)
hWndEditor = FindWindowEx_(GadgetID(#ComboBox), 0, 0, 0)
sysProc = SetWindowLongPtr_(hWndEditor, #GWL_WNDPROC, @ComboEditorProc())
  
While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend

DataSection
  scientists:    
  Data.s "Albert Einstein", "Isaac Newton", "Charles Darwin", "Guglielmo Marconi"
  Data.s "Galileo Galilei", "Leonardo da Vinci", "René Descartes", "Thomas Edison" 
EndDataSection
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply