what i am trying to do is check if the listView (column5) contains ANY items with the word ‘Yes’. If it does write ‘Great’, if the column does not contain any items at ALL with the word ‘Yes’ write ‘Bad’.
Whats happening now is my program is only writing Bad (the else statement) even if the column does contain an item that has the word ‘Yes’.
How can I fix this?:
foreach (ListViewItem item in listView1.Items) {
if (item.SubItems[5].Text.Contains("Yes")) {
// Do your work here
labelContainsVideo2.Text = "GREAT";
labelContainsVideo2.ForeColor = System.Drawing.Color.Green;
} else {
labelContainsVideo2.Text = "BAD";
labelContainsVideo2.ForeColor = System.Drawing.Color.Red;
}
}
If the last item in your list doesn’t contain “Yes”, then the output will be “BAD”, regardless of what the other items contain.
Try this instead…