Solved

ComboBox VB6 Change Size on Click

Posted on 2004-09-01
5
578 Views
Last Modified: 2010-05-18
I'm working with a form and I want to be able to change the size of the ComboBox so the entire contents can be read, but once a value is selected, the size of the combobox returns to fit into the form.

Ex.  123 - Piggly Wiggly Waffers

The comboBox should only be large enough to show 123 because of size constraints on the form, but when you click the down arrow you can see everything in the test box - 123 - Piggly Wiggly Waffers [the combobox expands to hold the size of the contents only when the user goes through the combobox]

Can this be done, I know in a delphi application I use the programmer did what I'm trying to do.  I appreciate your help in advance.
0
Comment
Question by:amangle
5 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 11956929
This can be done using the SendMessage API and the CB_SETDROPPEDWIDTH message.  Below is an example which sets the dropdown list to lWidth (in pixels).  Enjoy!

Option Explicit

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_SETDROPPEDWIDTH = &H160

Private Sub Command1_Click()

   Dim lWidth  As Long
   
   'Width of the dropdown in pixels
   lWidth = 250
   
  'Size the dropdown portion of the combo box using SendMessage
   Call SendMessage(Combo1.hwnd, CB_SETDROPPEDWIDTH, lWidth, ByVal 0)
     
End Sub
0
 
LVL 6

Assisted Solution

by:bkthompson2112
bkthompson2112 earned 35 total points
ID: 11956998
Hi Erick37,

or here's a link which shows how to set the width to be the same as the longest item:

http://www.vbaccelerator.com/home/VB/Tips/Change_the_drop-down_width_of_a_combo_box/article.asp

bkt
0
 

Author Comment

by:amangle
ID: 11958234
Thank you both for your help
0
 
LVL 6

Expert Comment

by:bkthompson2112
ID: 11958868
You're welcome.  Thanks for the 'A'.
0
 

Expert Comment

by:DingleBerry9876543210
ID: 13925970
Oh keen! Thanks buds!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now