How to Force a DropDown and Retract of the List in a Combo BoxID: Q124057
|
This article shows you how to send a message to the Combo box to force the
List portion to drop or retract at any time.
Usually, to drop the List portion of a Combo box, you click the dropdown
button located to the right of the Combo's edit box, or you can press the
F4 key when the control has the focus. To have the Combo box retract the
List portion, you click the dropdown button again, use the mouse or
keyboard to choose an item from the list, press the ESC or F4 key, or click
anywhere else on the screen.
To send the CB_SHOWDROPDOWN message to a Combo box of Style 0 - Dropdown
Combo or 2 - Dropdown List, call the SendMessage API function. If the
wParam parameter is any non-zero integer, the List will drop. If wParam
equals 0, the List will retract. Note that a Combo box of Style 1 (Simple
Combo) always has its list visible.
' Enter the following two lines as one, single line:
Declare Function SendMessage Lib "User" (ByVal hWnd As Integer,
ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
Const WM_USER = &H400
Const CB_SHOWDROPDOWN = (WM_USER + 15)
Sub Form_Load ()
combo1.AddItem "item# 1"
combo1.AddItem "item# 2"
combo1.AddItem "item# 3"
combo1.AddItem "item# 4"
End Sub
Sub Command1_Click ()
x% = SendMessage(combo1.hWnd, CB_SHOWDROPDOWN, 1, 0&)
End Sub
Sub Command2_Click ()
x% = SendMessage(combo1.hWnd, CB_SHOWDROPDOWN, 0, 0&)
End Sub
Sub Form_Paint ()
x% = SendMessage(combo1.hWnd, CB_SHOWDROPDOWN, 0, 0&)
End Sub
Sub Form_Resize ()
x% = SendMessage(combo1.hWnd, CB_SHOWDROPDOWN, 0, 0&)
End Sub
Additional query words: 2.00 3.00 ComboBox
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 4, 1999