This question is locked. New answers and comments are not allowed.
Hello everybody,
I have the following problem. When I remove a row in a RadGridView in a Master-Detail Form I get this error:
"It is not allowed to read or to write an instance marked for deletion."
This grid is linked to data as following way:
MyClass have a relation one to Many with MyClass2, MyClass.MyClass2 is a list implementing the relation
summary:
context.getall<MyClass>() -> bindingSource1 -> bindingSource2 (DataMember = "MyClass2")-> RadGridView
I catch the bindingSource2.ListChanged event to remove the object from context:
And then, when I remove a row in the grid and after run this code the "It is not allowed to read or to write an instance marked for deletion." error is thrown.
I don't know what I'm doing wrong. Can anyone help me?
Thanks and sorry for my English
P.S. I attached a screenshoot of the error
I have the following problem. When I remove a row in a RadGridView in a Master-Detail Form I get this error:
"It is not allowed to read or to write an instance marked for deletion."
This grid is linked to data as following way:
MyClass have a relation one to Many with MyClass2, MyClass.MyClass2 is a list implementing the relation
bindingSource1.DataSource = myContext.getAll<
MyClass
>();
bindingSource2.DataSource = bindingSource1;
bindingSource2.DataMember = MyClass2;
RadGridView.DataSource = bindinSource2;
context.getall<MyClass>() -> bindingSource1 -> bindingSource2 (DataMember = "MyClass2")-> RadGridView
I catch the bindingSource2.ListChanged event to remove the object from context:
bindingSource2.ListChanged +=
new
ListChangedEventHandler(b_ListChanged);
void
b_ListChanged(
object
sender, ListChangedEventArgs e)
{
if
(e.ListChangedType == ListChangedType.ItemDeleted)
{
context.remove(((BindingSource)sender).List[e.NewIndex])
}
}
And then, when I remove a row in the grid and after run this code the "It is not allowed to read or to write an instance marked for deletion." error is thrown.
I don't know what I'm doing wrong. Can anyone help me?
Thanks and sorry for my English
P.S. I attached a screenshoot of the error