Visual Basic Combo API
How to Show & Hide a Combo Box Dropdown List
     
Posted:   Wednesday January 8, 1997
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6, and VB3, VB4-16 with appropriate declarations
Developed with:   VB4-32, Windows 95
OS restrictions:   None
Author:   VBnet - Randy Birch
     
 Prerequisites
This code shows how to programmatically drop and retract the list portion of a combo box.

 BAS Module Code
None.

 Form Code
On a form, add a two command buttons and a combo box. Add the following code to the form:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
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 Form_Load()

   Combo1.AddItem "Item 1"
   Combo1.AddItem "Item 2"
   Combo1.AddItem "Item 3"

   Command1.Caption = "Show List"
   Command2.Caption = "Hide  List"

End Sub


Private Sub Command1_Click()

  'Drop the list
   Call SendMessage(Combo1.hWnd, CB_SHOWDROPDOWN, True, ByVal 0)

End Sub


Private Sub Command2_Click()

  'Close List
   Call SendMessage(Combo1.hWnd, CB_SHOWDROPDOWN, False, ByVal 0)

End Sub
 Comments
Run the project, and click Command1 to show the combo box list, or Command2 to hide it. This routine only applies to combo boxes whose style is 0 - Dropdown Combo, or 2 - Dropdown List.

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

 

Hit Counter