Click to See Complete Forum and Search --> : [RESOLVED] Delete DataGridView Row


GeoNav
October 23rd, 2009, 11:28 AM
Hi all, I have an unbound datagridview in my c# project in VS2008. I populate the Grid with details of files in a folder. When I try to clear the contents of the DataGridView by using

for (int n = 0; n < dgvFileList.Columns.Count - 1; n++)
{
dgvFileList.Columns.RemoveAt(n);
}
or

foreach (DataGridViewRow row in dgvFileList)
{
dgvFileList.Rows.Remove(row);
}
I am able to delete only certain number of the rows. I am getting an error "new uncommitted rows can not be removed". The RowCount of the grid also gives a wrong value.
But when I use this code, I get the correct value of the RowCount:-
int p = 0;
foreach (DataGridViewRow f in dgvFileList.Rows )
{
p += 1;
}
I tried using the above value in recursing through the rows, but still get the same error.
Could anyone help me?
Thanks
GeoNav.