Results 1 to 4 of 4

Thread: Combo box question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    how can I, using Code, force a combo box control to drop down the list? in VBA it's simple:

    combo1.dropdown

    How can I do the same in VB?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Use the CB_SHOWDROPDOWN API Message with the SendMessage Function, ie.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const CB_SHOWDROPDOWN = &H14F
    
    Private Sub Command1_Click()
        SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0&
    End Sub
    
    Private Sub Form_Load()
        Dim iIndex As Integer
        For iIndex = 1 To 10
            Combo1.AddItem "Item " & iIndex
        Next
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    ajyoung@pressenter.com


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    Is that the only way to do it? It just seems like it's pretty drawn out for such a simple thing. Having to make an API call to do something so simple. Thanks though

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    You could use the SendKeys Function, if you wanted to:
    Code:
    Private Sub Command1_Click()
        Combo1.SetFocus
        SendKeys "%{DOWN}", 1
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    ajyoung@pressenter.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width