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

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())
 
P

Paul E Collins

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.
 

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