I want to delete some rows from datagridview based on condition in c#,but at run time i find that row,though by debugging my code is working properly.
My code is as follows:-
foreach (DataGridViewRow item in this.dataGridView1.Rows)
{
if ((item.Cells["Start Time"].Value.ToString() != "22:00:00") || (item.Cells["Start Time"].Value.ToString() != "18:00:00"))
{
dataGridView1.Rows.Remove(item);
}
}
dataGridView1.Rows.Remove(item);
Instead of this line,I have even tried
dataGridView1.Rows.RemoveAt(item.Index)
i have even tried to delete rows from datatable and then bind in datagridview ,but nothings helped me.
why my above code fails to delete record in datagridview,PLZ help me out.
Kanimozhi ShivakumarRank #6,889 · 254 reputationPosted Aug 13, 2018, 3:39 AM EDT
Jaish MathewsRank #225 · 11K reputationPosted Aug 11, 2018, 6:11 AM EDT
ejaz mirzaRank #2,930 · 491 reputationPosted Aug 10, 2018, 10:01 PM EDT
priyankaRank #7,741 · 235 reputationPosted Aug 10, 2018, 10:12 PM EDT
ejaz mirzaRank #2,930 · 491 reputationPosted Aug 10, 2018, 10:14 PM EDT
priyankaRank #7,741 · 235 reputationPosted Aug 10, 2018, 10:19 PM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Aug 11, 2018, 6:51 AM EDT
Yogesh GhorpadeRank #2,756 · 509 reputationPosted Aug 13, 2018, 2:47 AM EDT
priyankaRank #7,741 · 235 reputationPosted Aug 14, 2018, 12:36 AM EDT
Sirisha KRank #2,567 · 544 reputationPosted Aug 14, 2018, 10:21 AM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Aug 15, 2018, 10:13 PM EDT
ejaz mirzaRank #2,930 · 491 reputationPosted Aug 10, 2018, 10:30 PM EDT
Sirisha KRank #2,567 · 544 reputationPosted Sep 3, 2018, 12:07 AM EDT
Karthik Ramachandran107 reputationPosted Aug 31, 2018, 9:55 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts