tags:

views:

473

answers:

2

What is the best way to check if there is atleast a selected item in a listview or not in an if statement?

+4  A: 

I'm not entirely sure what you are asking. Do you want to make sure at least 1 item is selected before running an action? If so the following should work

if ( listView.SelectedItems.Count > 0 ) { 
  // Do something
}

Or are you curious if a particular item is selected? If so try the following

if ( listView.SelectedItems.Contains(someItem)) { 
  // Do something
}
JaredPar
A: 
if( listView.SelectedItems.Count > 0 ){
 // do stuff here
}
Winston Smith