Combobox text remains selected

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
 
B

Bruce Wood

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?
 
M

Michael Jackson

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
 
T

Truong Hong Thi

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.
 
B

Bruce Wood

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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top