Link to home
Start Free TrialLog in
Avatar of aerelorn
aerelorn

asked on

Drop-down List Combobox

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.
Avatar of Ruchi
Ruchi

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
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

Avatar of aerelorn

ASKER

Thanks Ruchi, works perfectly.  Please repost as an answer.
ASKER CERTIFIED SOLUTION
Avatar of Ruchi
Ruchi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial