The new vbAccelerator Site - more VB and .NET Code and Controls

Make a ComboBox drop down when you press the down arrow key

Author:

Steve McMahon(steve@vbaccelerator.com)

Keywords:

API,Combo Box,Windows Controls

Updated:

12/10/98

Other Tips
All Tips
By Date
By Subject


API (33)
Bit
Manipulation (3)

Clipboard (3)
Combo
Box (5)

Desktop (3)
GDI (13)
Graphics (13)
Internet (2)
Interprocess
Comms (3)

Keyboard (2)
Mouse (1)
Shell (1)
Sprites (1)
Subclassing (3)
Text
Box (2)

Windows (11)
Windows
Controls (10)



Submit


Drop-down combo boxes by default drop down when you press the F4 key. However, not many users know this, and you can make a combo box easier to use by making it drop down in response to the down arrow key instead.

Start a new project and add a module. Then add the following code to the module:


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 Const CB_GETEXTENDEDUI = &H156
Private Const CB_SETEXTENDEDUI = &H155

Public Property Let ComboExtendedUI(ByRef cboThis As ComboBox, ByVal bState As Boolean)
&nbsp &nbsp ' Set whether combo box drops down using the Down Arrow or not: &nbsp &nbsp SendMessageLong cboThis.hwnd, CB_SETEXTENDEDUI, Abs(bState), 0
End Property
Public Property Get ComboExtendedUI(ByRef cboThis As ComboBox) As Boolean
&nbsp &nbsp ' Get whether combo box drops down using the Down Arrow or not: &nbsp &nbsp ComboExtendedUI = (SendMessageLong(cboThis.hwnd, CB_GETEXTENDEDUI, 0, 0) 0)
End Property

To try out a the function, add a Combo box and a Check box to your project's form. Then add this code:

Private Sub Check1_Click()
&nbsp &nbsp
&nbsp &nbsp ' Toggle whether the Combo box will drop
&nbsp &nbsp &nbsp &nbsp ' down when the down arrow is clicked or
&nbsp &nbsp &nbsp &nbsp ' not:
&nbsp &nbsp ComboExtendedUI(Combo1) = (Check1.Value = Checked)
End Sub

Private Sub Form_Load()
Dim i As Long
&nbsp &nbsp
&nbsp &nbsp ' Add some test items:
&nbsp &nbsp For i = 1 To 20
&nbsp &nbsp &nbsp &nbsp Combo1.AddItem "Test Item " & i
&nbsp &nbsp Next i
End Sub

Start the project. When the project runs, you have to use to F4 box to make the combo box drop down. When you check the combo box, the down arrow key drops the box down instead.


&nbsp

Related Tips and Articles:

&nbsp

AboutContributeSend FeedbackPrivacy

Copyright 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 12/10/98