Datagridview Winforms Add or Delete Rows in Edit Mode with Collection Binding

Posted by user630548 on Stack Overflow See other posts from Stack Overflow or by user630548
Published on 2011-03-12T15:01:26Z Indexed on 2011/03/13 0:10 UTC
Read the original article Hit count: 354

Filed under:
|
|
|

In my datagridview, I bind a List of objects named 'ProductLine'. But unfortunately with this approach I cannot 'Add' or 'Delete' rows to the datagridview in edit mode. When I create a fresh new order I can Add or Delete rows but once I save it and try to open it in Edit then it doesn't let me 'Add' or 'Delete' (via keyboard).

Any idea?

Here is the code for this:

If it is a fresh Order then I do something like this:

private void Save(){
   for (int i = 0; i <= dtgProdSer.RowCount - 1; i++)
   {
      if ((itemList != null) && (itemList.Count > i))
           productLine = itemList[i];
      else
           productLine = new ProductLine();
      productLine.Amount = Convert.ToDouble(dataGridViewTextBoxCell.Value);
    }
}

And if it is an Edit then in the Form_Load I check ProductId is NON Zero then I do the following:

private void fillScreen{
    dtgProdSer.DataSource = itemList;
}

But with this I cannot Add or Delete Rows in Edit mode.

Any advise is greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms