I have a loop in the action of the button to delete empty items in my ListView , but the problem is that when I click the button, it successfully deletes only those items that were single. I mean: it does not delete elements when there are several of them:
Example:
a1 = "" a2 = "qwe" a3 = "" a4 = "" a5 = "qwe"
therefore, after clicking the button, the result will be:
a2 = "qwe" a3(or a4 idk) = "" a5 = "qwe"
I think this is an easy logical problem, but I cannot figure it out.
for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].SubItems[2].Text == "") { listView1.Items[i].Remove(); } }
Thus, the problem is that the loop skips one check after it finds an empty value. How to fix it?
source share