Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

opening a combobox without the mouse

i have a combobox that i want the user will be able to display the combo list without clicking the mouse, but by pressing a combinations of keybords keys, for example shift + a. how do i do this?
any help will be much appriciated!
yny
0
yny
Asked:
yny
  • 2
1 Solution
 
peterwestCommented:
Hi there,

First of all put the following in a module:

Public Const CB_SHOWDROPDOWN = &H14F

Public Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)


Now set the keypreview property for the form you are working on to true and put this code in the KeyDown event of the form:

    'Declare local variables
    Dim lRetVal As Long

    'If alt was held down then...
    If Shift = 4 Then
       
        'Look at the key that was pressed with ALT
        Select Case KeyCode
        Case 64 'A pressed with ALT
             lRetVal= SendMessageByNum(Combo1.hWnd,CB_SHOWDROPDOWN,0,0)

        End Select

     End If


You should now find that if the user pressed ALT+A when any control on the form has focus then the Combo1 combobox will drop down.

Hope this is what you're after.

Pete

0
 
ynyAuthor Commented:
that was exactly what i was looking for.
just a small remark: in order to show the dropdown list, the third parameter of the function must be 1 (nonzero).
thanks very much
yny
0
 
peterwestCommented:
Cheers,

Sorry about that last param - I was in a bit of a rush to get the answer sorted out and didn't read the API manual properly.

Pete

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now