Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with .net Combo Boxes

I have a form which has a Combo Box Control. I have selected the drop down style property to DropDown. I have also set the DropDown Width to 250. I have set the auto complete mode to suggest and the auto complete source to listitems. it works absolutely fine when i click on the drop down. but when i type in somethin, the auto complete mode activates a drop down which has a small width.

any help appreciate. i wanna know how to increase the width of the auto complete drop down via code so that the list items are viewed properly. I am using C#

like image 833
reggie Avatar asked Mar 10 '10 17:03

reggie


2 Answers

Yes, this is by design. ComboBox uses the SHAutoComplete API function to implement the autocomplete feature. Note the declaration, the function takes a handle to the text box portion of the ComboBox. As such, it has no idea that it is actually providing autocomplete info for a ComboBox instead of a TextBox. Accordingly, there is nothing it can do to compensate for the non-standard dropdown width you use.

Well, that explains why it doesn't work. Fixing it is technically possible but quite ugly. You would have to run code in the KeyUp event and use EnumTheadWindows() to find the autocomplete window handle. Then you can use SetWindowPos() to make it larger. There is already code similar to this in ComboBox.cs (AutoCompleteDropDownFinder.FindDropDowns), use the Reference Source or Reflector to help you get this right. Good luck!

like image 137
Hans Passant Avatar answered Nov 15 '22 17:11

Hans Passant


EDIT:
I removed my first suggestion to come up with a new link:

Actually its possible to control the width of the Autocomplete dropdown box, but its a little bit tricky and involves using win API extensively ...

Combobox too small when doing Suggest

like image 2
tanascius Avatar answered Nov 15 '22 17:11

tanascius