I have gridview, it’s datasource is list<string> and I added one checkbox column to select rows that I want to delete then I press delete.
attachdatagrid.DataSource = ConceptProperties.conceptsattachmentsfilename[mouseOverIndex].Select(x => new { FileName = x }).ToList();
the problem is my
gridview EditMode
properties is EditOnKeystroke, and when I wrote
if ((bool)dr.Cells[0].Value != false)
{
found = true;
ConceptProperties.conceptsattachments[mouseeditIndex].RemoveAt(dr.Index);
ConceptProperties.conceptsattachmentsfilename[mouseeditIndex].RemoveAt(dr.Index);
attachdatagrid.Rows.RemoveAt(dr.Index);
}
I got exception :
Rows cannot be programmatically removed unless the DataGridView is
data-bound to an IBindingList that supports change notification and
allows deletion.
how can I delete the row?
You’d better bind your grid to a binding source and do all manipulations on it(the binding source) rather than the list itself.
You can do that by dropping a binding source component to your form, then setting its data source to the list and the grid’s data source to the binding source.
IList doesn’t support change notifications. IBindingList(which binding source implements) does.