list box no selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

if(listBox.SelectedItem.Text != null)
{
// test
}

This code gives exception if no item is selected in the list box, how can I
check if any item is selected or not?
 
if(listBox.SelectedItem.Text != null)
{
// test
}

This code gives exception if no item is selected in the list box, how can
I
check if any item is selected or not?

if(listBox.SelectedIndex == -1)
{
// no items selected
}
 
Back
Top