Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect if no selected item on ComboBox is chosen?

In my ComboBox, the field is blank before users click it and choose any item. So without users click on the ComboBox, it remains empty. How do we check whether the ComboBox is empty or not?

This codes gives me an error because there is no item selected yet:

if( ComboBox.SelectedItem.ToString().Equals("") )
{
     //do something
}
like image 683
Hendra Anggrian Avatar asked Oct 13 '12 19:10

Hendra Anggrian


People also ask

How do you check if an item was selected from a ComboBox in VB net?

int a = ComboBox. SelectedIndex. CompareTo(-1); if (a == 0) { MessageBox. Show("Please select something."); } else { // do something if combo box selection is done.! }

Which event can be used to detect changes in list ComboBox selection?

You can use "ComboBoxItem. PreviewMouseDown" event.

How check ComboBox is empty in VB net?

A ComboBox displays a text box combined with a ListBox, which enables the user to select items from the list or enter a new value. Conditionally testing SelectedItem or SelectedIndex will not handle the case of the user entering a new value from another input device like a keyboard. Use string. IsNullOrEmpty(comboBox1.


1 Answers

if( ComboBox.SelectedItem == null ) {
   // do something
}
like image 165
Jcl Avatar answered Sep 27 '22 22:09

Jcl