Page 1 of 1

Combobox question

Posted: Sun Feb 26, 2012 12:03 am
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

Re: Combobox question

Posted: Sun Feb 26, 2012 1:56 am
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

Re: Combobox question

Posted: Sun Feb 26, 2012 9:58 am
by karu
Big thanks :)

Re: Combobox question

Posted: Sun Feb 26, 2012 10:08 am
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