[ACCEPTED]-C#: How do you make sure that a row or item is selected in ListView before performing an action?-winforms
Accepted answer
I'm not entirely sure what you are asking. Do 5 you want to make sure at least 1 item is 4 selected before running an action? If so 3 the following should work
if ( listView.SelectedItems.Count > 0 ) {
// Do something
}
Or are you curious 2 if a particular item is selected? If so 1 try the following
if ( listView.SelectedItems.Contains(someItem)) {
// Do something
}
if( listView.SelectedItems.Count > 0 ){
// do stuff here
}
0
You can also check the value of a selected 1 item or perhaps bind it to a string if needed:
//Below is with string
String member = (String)ListView1.SelectedValue;
//Below is with any class
AnyClass member = (AnyClass)ListView1.SelectedValue;
String StaffID = member.StaffID;
int taskId = Convert.ToInt32(itemRow.SubItems[0].Text);
string 2 taskDate = itemRow.SubItems1.ToString();
string 1 taskDescription = itemRow.SubItems[2].ToString();enter image description here
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.