Solved

ComboBox VB6 Change Size on Click

Posted on 2004-09-01
5
583 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 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