Solved

ComboBox VB6 Change Size on Click

Posted on 2004-09-01
5
596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 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