wariar
asked on
combo boxes and the keyboard
Is there a way I can know if the combo box is pulled down or a selection is made from the keyboard or the mouse?
ASKER
Thanks yowkee !!!
I guess I should have been more specific with my question.
How do I know if I've used the KEYBOARD or the MOUSE to either pull down the combo box or select an item from the list?
I guess I should have been more specific with my question.
How do I know if I've used the KEYBOARD or the MOUSE to either pull down the combo box or select an item from the list?
wariar,
In this case, you could just use a variable to check about it.
Declare a variable iCheck in Form module. Set iCheck to 1 in combo1 mousedown event, set icheck to 2 in combo keydown event.
Then you could just check the variable to determine user has used mouse or keyboard to select an item and never select (could combine with above selection checking).
Regards.
In this case, you could just use a variable to check about it.
Declare a variable iCheck in Form module. Set iCheck to 1 in combo1 mousedown event, set icheck to 2 in combo keydown event.
Then you could just check the variable to determine user has used mouse or keyboard to select an item and never select (could combine with above selection checking).
Regards.
ASKER
yowkee,
Thanks again. I tried what you suggested but with a boolean variable. It seems to work. I appreciate the quick response.
wariar.
Thanks again. I tried what you suggested but with a boolean variable. It seems to work. I appreciate the quick response.
wariar.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could use SendMessage to get these info from combo box. To check whether it's pull down, send message CB_GETDROPPEDSTATE. To check any item being selected, send message CB_GETCURSEL.
For example:
----
' You may change the code to the place you want to do the ' checking
Const CB_GETDROPPEDSTATE = &H157
Const CB_GETCURSEL = &H147
Const CB_ERR = (-1)
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Sub Command1_Click()
Dim lDrop As Long
lDrop = SendMessageLong(Combo1.hwn
If lDrop Then
MsgBox "Drop Down!"
Else
MsgBox "Not drop down"
End If
End Sub
Private Sub Command2_Click()
Dim lSel As Long
lSel = SendMessageLong(Combo1.hwn
If lSel <> CB_ERR Then
MsgBox "Selected: " + Combo1.List(lSel)
Else
MsgBox "No item being selected!"
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "A"
Combo1.AddItem "B"
Combo1.AddItem "C"
Combo1.AddItem "D"
Combo1.AddItem "E"
End Sub
-----
Regards.