Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm using a combo box with .net4 c# and I need to set the width of the drop down list dynamically. The list of stings are added from a SQL query at run time.

The combo box is set to the following:
AutoCompleteMode:SuggestAppend
AutoCompleteSource:ListItems
DropDownStyle:Simple

This gives a list of matches while you type, but the width has to be manually adjusted for long strings.

I have used the suggested code in here Adjust combo box drop down list width to longest string width[^] and that works for the drop down list when DropDownStyle:DropDown, but if you type in some text, the problem noted is still apparent.

Can anyone point me to a solution?
Posted

1 solution

Have you run it under the debugger?

Why don't you get the longest string size (in pixels) when the list is populated/bound. At that point, you don't have to cylce through the items in the list to see which one is the longest, and you can set the width one time.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900