Solved

combo boxes and the keyboard

Posted on 1998-06-29
5
265 Views
Last Modified: 2010-05-03
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?
0
Comment
Question by:wariar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:yowkee
ID: 1464523
wariar,

  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.hwnd, CB_GETDROPPEDSTATE, 0,_                             0)
    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.hwnd, CB_GETCURSEL, 0, 0)
    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.
0
 

Author Comment

by:wariar
ID: 1464524
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?
0
 
LVL 4

Expert Comment

by:yowkee
ID: 1464525
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.
0
 

Author Comment

by:wariar
ID: 1464526
yowkee,

Thanks again. I tried what you suggested but with a boolean variable. It seems to work. I appreciate the quick response.

wariar.
0
 
LVL 4

Accepted Solution

by:
yowkee earned 50 total points
ID: 1464527
wariar,

  I assume I could propose it as answer. :)

----
 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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question