Solved

ComboBox VB6 Change Size on Click

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

679 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