How to test if an item has been selected of a combo box

  • Thread starter Thread starter ree
  • Start date Start date
R

ree

I have two combo boxes on a dialog window.

The aim is to check the the strings of the items. But if no items are
selected then this line crashes the program.

if (comboBox1.SelectedItem.ToString() == comboBox2.SelectedItem.ToString())
 
ree said:
if no items are selected then this line crashes
the program.
if (comboBox1.SelectedItem.ToString() ==
comboBox2.SelectedItem.ToString())

If the SelectedIndex property is -1, there is no current selection.

P.
 
Back
Top