Check if combobox value is empty

Check the selected index value of dropdown equals -1

if (Comboboxid.SelectedIndex == -1){
    MessageBox.Show("Your message.");
}

Use

if (comboBox1.SelectedIndex == -1)
{
   MessageBox.Show("Please select a value");
   return;           
}

Note: SelectedIndex will be set to -1 when SelectedValue is blank ONLY when FormattingEnabled is true. See here.


The code should work. Although I will also set SelectedIndex as well......

if (this.comboBox1.SelectedItem == null || this.comboBox1.SelectedIndex == -1)

you mean "When I dont touch it, the program will start without message box. Whats wrong?" is there any code related with "touch it"


if (string.IsNullOrEmpty(comboBox1.Text)) or if (comboBox1.SelectedIndex == -1)