#Combo Box List Width
7 messages in this thread
Hi,
Does anyone know if there is a way to get the combo box pulldown
list to size itself to the width of the longest string in the list. I
have an application where I want to show the users a one character code
followed by a description of the code in the pulldown list. When they
pick from the list, I'll just enter the one character code into the box for
them. The combobox itself is sized to show only a single character and
when I pull down the list, the list box only extends to the end of the
control thus truncating my descriptions. Any help would be appreciated.
Thanks. — Rich Cuti
There are 2 Replies.
Rich,
Take a look at the .width property for your combobox. I haven't tried it
but you should be able to reset the width of the combobox to the width
needed for the descriptions when it's initially selected. Then reset the
width back to the original once a new selection has been made.
–dennis
There is 1 Reply.
Hi,
I did a quick sample code for style 2 combobox. This should get you on
your way. Look in the Knowledge Base for information on the
GetSystemMetrics for additional parameters.
Don Funk
Const SM_CYCAPTION = 4
Sub Form_Click ()
S% = TextWidth("AA")
X% = GetSystemMetrics(SM_CYCAPTION)
If Combo1.Style = 2 Then
Combo1.Move 10, 10, S% + X%
End If
Combo1.AddItem "AA"
End Sub
There are 2 Replies.
Thanks. I'll try it. Does this work with style 0? I need my combo boxes
to have an edit area too. — Rich Cuti
There is 1 Reply.
Hi Rich,
I did the easiest one<g>. You will need to figure what the white space
is between the button and edit portion. As a quick solution which may not
work on all systems is to just add some constant which will account for this
space. Different systems may have different "white space".
Don Funk
Hi,
I gave both solns a try (yours and Dennis's) and they did resize the
comboboxes but as I feared, they overlap other controls (this is a data
entry type form I'm building) and thus mess up each other. I need the list
to expand to width without the actual control width changing. I guess I
may have to build my own "pop-up" form from a list box to do what I want.
I'll see. Thanks guys. — Rich Cuti