Click to See Complete Forum and Search --> : Combo box question
netSurfer
Jan 26th, 2000, 03:33 AM
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?
Aaron Young
Jan 26th, 2000, 03:46 AM
Use the CB_SHOWDROPDOWN API Message with the SendMessage Function, ie.
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
netSurfer
Jan 26th, 2000, 03:50 AM
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
Aaron Young
Jan 26th, 2000, 04:10 AM
You could use the SendKeys Function, if you wanted to:
Private Sub Command1_Click()
Combo1.SetFocus
SendKeys "%{DOWN}", 1
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.