Clearing last item from combobox?

B

Brett Romero

After I remove all items from a combobox, the last selected item
remains in the display area. I've tried:

mycbox.SelectedText = string.Empty;

and

mycbox.refresh();

How do I clear the display area of a combobox after removing all of its
items?

Thanks,
Brett
 
M

Morten Wennevik

Hi Brett,

As Dave more or less pointed out, use the Text property to manipulate the
Text field of the ComboBox.

mycbox.Text = ""; // or String.Empty or null

should work.

When you do a Clear on the ComboBox you already clear SelectedText and
SelectedValue as well. SelectedIndex is set to -1 to indicate no item is
selected. The Text property is cleared as well if the ComboBox style is
set to DropDownList, but a regular ComboBox allows for manual editing of
the Text property and will therefore not be cleared even if the items are
removed.
 

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