Clear the text from a ComboBox

yulyos

Well-known member
Joined
Jun 4, 2004
Messages
67
Location
Israel
Programming Experience
5-10
Hi,

I am using Visual Basic 2005 Express Edition

I have in my form ComboBox:
ComboBox.DropDownStyle = ComboBoxStyle.DropDownList

I am trying to clear the text from the ComboBox:
ComboBox.Text = ""

It's not working

I don't want to clear all the items:
ComboBox.Items.Clear()

Can somebody tell how to clear the text from the ComboBox.

Thanks in advance
 
From MSDN: "If you set the DropDownStyle property to DropDownList, you can select only valid values from the list."
The common way to handle this situation is to add an item to the list such as 'Select something'. When you want to "clear" the comboBox, set the SelectedIndex to the index of that item.
You can also try setting the selectedIndex to -1 meaning nothing is selected.
 
Back
Top