Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to drop down a combobox programmatically? 3

Status
Not open for further replies.

EwS

Programmer
Dec 30, 2002
398
US
I need to fire the DropDown event when the user clicks in the combobox or pressed the down arrow. How do I do this?

Thank you.
 
Const WM_USER = &H400
Const CB_SHOWDROPDOWN = &H14F
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Long) As Long
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim i As Long
If KeyAscii = 13 Then
i = SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, 0&)
End If
End Sub
 
I guess this is the same thing:

Combo1.SetFocus
SendKeys "%{DOWN}"

Just use it in your click_event and KeyPress event (trap for AscII 13 (=enter key).

Plain and simple.

Good luck.

Patrick
 
It's not quite the same thing. SendKeys is actually rather a nasty hack that MS included in VB. I tend to avoid it whenever I can.
 
I aggree with you partial.
When sendkeys is used withoud really setting focus to the object, bad things can occur (I even deleted an access table once because I forgot to set focus to the form when using sendkeys (DEL)).
However, if you set focus to the control, I can't think of anything that could go wrong.

Patrick.
 
>if you set focus to the control, I can't think of anything that could go wrong

I can.

But when using it in the click event, then probably not.
 
Hello DrJavaJoe or others,

Do you suggest any good articles, links, etc. pertaining to using the SendMessage API, or on messaging in general? This is an area where I can follow what is being done by others but have no idea how to go about learning how to set things up on my own. Thanks for any ideas and/or suggestions!

Have a great day!

j2consulting@yahoo.com
 
hmmm, try searching somewhere like for sample code or just do a google search, your bound to get tons of hits.

"Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top