Datagridview Winforms Add or Delete Rows in Edit Mode with Collection Binding
- by user630548
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.