How can I set the combo's text to be the same as the text for one of the
combo's Items, but still have the text display UNSELECTED
When I set up the data in a combo box "combo" as follows:
combo.Items.Clear();
combo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
combo.BeginUpdate();
combo.Items.Add( "Item 1" );
combo.Items.Add( "Item 2" );
combo.Items.Add( "Item 3" );
combo.Items.Add( "Item 4" );
combo.Text = "Item X";
combo.EndUpdate();
The combo displays the text "Item X" UNSELECTED and shows none of the items in the drop-down list selected.
If instead of
combo.Text = "Item X";
I say
combo.Text = "Item 2";
The combo displays the text "Item 2" SELECTED and shows the list entry containing "Item 2" as selected in the drop-down list. This is very clever of the combo, but its not what I want.
I want the combo to display the text "Item 2" UNSELECTED as it does for "Item X" above.
So how can I set the combo's text to be the same as the text for one of the
combo's Items, but still have the text display UNSELECTED
cheers,
Rod

How to prevent Combo Box automatic selection of text?
Boris Mueller
Its a (hopefully temporary) workaround, not a solution.
Selecting a value in a dropdownlist combo does not highlight the text displayed by the combo, but setting the text of a dropdown combo does highlight the text displayed by the combo if that text is the same as one of the elements in the combo list.
I have both dropdown and dropdownlist combos on a form, all with default values and I want them to look the same - with no highlighting of the text displayed by the combos when the form is first displayed.
Yes.
When a user selects a new value from a combo list the text is highlighted, but the highlight is removed when the combo loses focus.
Northwester
I think the work around proposed by Rod may be inconvenient if the user wants to get text from the combobox.
But Why do you want this behaviour
Do users change the selection of combobox further more
soni_ace
fibonacci1123
combo.Text = "Item 2 ";
instead of
combo.Text = "Item 2";
any others
JavaBoy
I tried Select(0,0) which should have gotten rid of the selection, but it didn't work either from directly after the assignment to combo.Text or from the combo's selection change handler.
I think Select(0,0) is probably the answer, but where do I need to call it from
Romantic_touch
Actually, if you set the DropDownStyle property to DropDownList, you can select only valid values from the list. If you set the DropDownStyle property to DropDown, you can type any value in the editable area of the ComboBox.
so if you really want to highlight the text in a DropDownList style combobox, I'm afraid you should custom that control.
Alastair Q