CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Threaded View

  1. #1
    Join Date
    Aug 2006
    Posts
    93

    [RESOLVED] Delete DataGridView Row

    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.
    Last edited by GeoNav; October 23rd, 2009 at 11:31 AM. Reason: Add VS Version

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured