What is the best way to check if there is atleast a selected item in a listview or not in an if statement?
views:
473answers:
2
+2
Q:
C#: How do you make sure that a row or item is selected in ListView before performing an action?
+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
2009-05-03 15:19:05