How to Detect the Retraction of a Combo Box Dropdown ListID: Q124058
|
There is no built-in Visual Basic event that gets fired when the dropdown list portion of a Combo box is retracted. This article shows by example how to fire such an event by sending a message to the Combo box.
The Combo box can be polled to obtain the status of its dropdown list. By
constantly sending a CB_GETDROPPEDSTATE message to the Combo box inside a
timer event, you can detect the moment the list is retracted. The Windows
API SendMessage() is used for this purpose. SendMessage returns a non-zero
integer if the dropdown list is presently visible and 0 otherwise.
' 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_GETDROPPEDSTATE = (WM_USER + 23)
Sub Form_Load ()
combo1.AddItem "item# 1"
combo1.AddItem "item# 2"
combo1.AddItem "item# 3"
combo1.AddItem "item# 4"
End Sub
Sub Combo1_DropDown ()
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Sub Timer1_Timer ()
status% = SendMessage(Combo1.hWnd, CB_GETDROPPEDSTATE, 0, 0&)
If Not status% Then
'Insert the code for the retraction event here
MsgBox "DropDown List Retracted!"
Timer1.Enabled = False
End If
End Sub
Additional query words: 2.00 3.00 ComboBox
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 22, 1999