AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

How to show and hide a combo box dropdown list

This code shows how to programmatically drop and retract a combo box list portion.

Declarations

Add the following code to the declarations section of a basic module.

Public 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

Public Const CB_SHOWDROPDOWN = &H14F  

Form Code

Add 2 command buttons and a combo box to a form.  Add the following code to the form.

Sub Form_Load()
   Combo1.AddItem "Item 1"
   Combo1.AddItem "Item 2"
   Combo1.AddItem "Item 3"
End Sub


Private Sub Command1_Click()
  'label this button Show List
   Dim r as Long
   r = SendMessageLong(Combo1.hWnd, CB_SHOWDROPDOWN, True, 0)
End Sub


Private Sub Command2_Click()
  'label this button Hide List
   Dim r as Long
   r = SendMessageLong(Combo1.hWnd, CB_SHOWDROPDOWN, False, 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.

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/