How to remove row which has one or more empty or null cell ?
Posted
by Harikrishna
on Stack Overflow
See other posts from Stack Overflow
or by Harikrishna
Published on 2010-05-13T05:25:50Z
Indexed on
2010/05/13
5:44 UTC
Read the original article
Hit count: 137
I have datagridview on my winform. I am displaying records in the datagridview. Now after displaying the records on the datagridview, I want to remove the row from datagridview which has one or more empy cells that is no value in the cell for that row. So for that I am checking each cell for every row if there is any cell empty or null then I remove that rows using RemoveAt()
function.
My code is :
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (string.IsNullOrEmpty(dataGridView1.Rows[i].Cells[j].Value.ToString()))
{
dataGridView1.Rows.RemoveAt(i);
break;
}
}
}
© Stack Overflow or respective owner