Solved

ComboBox VB6 Change Size on Click

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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