Solved

Drop-down List Combobox

Posted on 2000-02-14
5
161 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

773 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