Solved

Drop-down List Combobox

Posted on 2000-02-14
5
159 Views
Last Modified: 2010-05-02
Howdy.

I'm writing a program with many small forms that have large numbers of drop-down list comboboxes.  To save space on the forms, each combo box is rather small.  However, the items in the list are long, and get cut off.

Is there any way to expand the list to be the size of the longest item when it drops down, or to expand the control itself before the list drops, then put it back at the original size after the user makes their selection?

I'd rather not use a scrollbar, if at all possible.

Thanks.
0
Comment
Question by:aerelorn
5 Comments
 
LVL 9

Expert Comment

by:Ruchi
ID: 2519994
Something like this..

'Add 1 ComboBox to your form.
'Insert the following code to your form:

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const CB_SETDROPPEDWIDTH = &H160

Private Sub Form_Load()
'Replace the '190' below with your desirable ComboBox dropdown width.
r = SendMessageLong(Combo1.hwnd, CB_SETDROPPEDWIDTH, 190, 0)
End Sub
0
 

Expert Comment

by:ramaswamy_ravi
ID: 2519997
Hi,

One easy way is to expand the width in the GotFocus event and reduce the width to the original size in the LostFocus event.

I think, there are also API calls to determine if the combobox is dropped-down or closed. I will later look into it and see if there is one.


The other solution is you can use 3rd party controls, where they treat the text area and the drop-down area as two different items. You can set the column width of the drop-down area and the text area at design time and not worry about it in the code. This is changing the free way entirely.

Please let me know, if this works for you.

Ravi

0
 

Expert Comment

by:vinoopauls
ID: 2520011
0
 

Author Comment

by:aerelorn
ID: 2520676
Thanks Ruchi, works perfectly.  Please repost as an answer.
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 100 total points
ID: 2520750
Thanks, aerelorn.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

707 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