I have a small problem that has been annoying me for some hours.
In my WinForms (.NET 3.5) application I create some ComboBoxes (DropDownStyle = DropDown) in a TableLayoutPanel at runtime and fill it with strings. The ComboBoxes are configured to resize automatically (Anchor = Left | Right).
The problem is that whenever the ComboBoxes are resized (i.e. the dialog is resized), the editbox portion of the ComboBox gets selected/highlighted entirely. In my opinion this creates a very confusing effect for the customer which I want to avoid.
The problem doesn't appear if the ComboBox has a fixed size.
Also note that changing the DropDownStyle is not an option – I need the possibility to enter text manually.
I already tried messing around with overriding the OnPaint method, which didn't quite work.
I also tried clearing the selection in the ComboBox.Resize event, which worked in a way, but seemed like a very ugly solution – there was a lot of flicker, intentionally selected text became deselected and I would have to add the event handler to each and every ComboBox on my dialog.
Is there a better solution to this problem?
Thank you in advance.
This is an old question, but I found it searching for an answer and ended up implementing my own solution. Might as well post it here, right?
This WinForms bug doesn't affect selected ComboBoxes, so by ignoring the ones with Focus, we take care of the problem of losing current selections.
Taken care of by the foreach loop. Put it in InitializeComponent() or your .ctor if you don't want to break the designer, or have the designer break this.
I'm only seeing flicker if I resize very fast, but I'm on Win7 so it might be different on XP.