Combobox text remains selected

  • Thread starter Thread starter Michael Jackson
  • Start date Start date
M

Michael Jackson

In my VB.NET 2003 1.1 applicatioin, I'm setting SelectedIndex = 1 on several
comboboxes at formload. This works fine, however, the text in the combobox
text portion remains selected (blue), and is very annoying.

This only started happening when I began setting the SelectedIndex via code.

What am I doing wrong?

Michael
 
I have the same problem in a version of ComboBox inherited from
System.Windows.Forms.ComboBox. My inherited version does
autocompletion. However, when I set the combo box to allow users to
type freely (required for auto completion mode), the text portion
remains selected, as you've found.

Is this happening for you on a native ComboBox, or an inherited version
that you wrote, as it is for me?
 
I'm using the native combobox.
Problem went away when I set style to DropDownList.

I want the DropDown style to allow user to type... maybe setting selected
text to nothing or similar.

Michael
 
You can set SelectionLength = 0, or call Select(0, 0) method fo that
combobox to reset its selection state.
If you want to move focus to another control instead, call that
control's Focus method.
 
That's the odd thing: I tried inserting SelectionLength = 0 in various
On... methods of my inherited ComboBox and it had no effect: the
ComboBox insisted on highlighting its contents anyway. I have it on my
list of things to do to investigate this more thoroughly, although I've
already wasted a day on it.

About a month ago I overrode every On... method I imagined could be
relevant, and printed out the selection point and the selection length
at each point. The text mysteriously "selected itself" after focus left
the control, I think. Even after I managed to tame the thing a little,
I could switch to another tab (it's on a TabPage) and then flip back
and the text would be selected again. It was extremely frustrating, so
I gave up.

I'll have to try again when I get a chance, to see if I can crack this
nut. :-)
 
Back
Top