Solved

Drop-down List Combobox

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

919 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

21 Experts available now in Live!

Get 1:1 Help Now