I'm having the same issue. In my case, the delete fails because another user has updated the record and my stored procedure aborts the delete, returning an error.
To get around the DataGridView issue, I implemented an UnDelete(child) in the Business class and call it when the Save fails. I also question whether this is the best way to re-add the child on a failed delete.
Well, I'm doing something wrong then. (Probably many things wrong.)
I tried a CancelEdit() on the collection, but it didn't recover the deleted item from the DeletedList. Looking further, the EditLevel was 0 in the collection object prior to the CancelEdit.
So, I tried to do a BeginEdit() on the collection prior to assigning it to the binding source. But, when I try to save the changes, I get a CSLA validation exception "Object is still being edited and can not be saved". So, before the save, I added temp.ApplyEdit() to the cloned collection. Then, if it succeeds, I ApplyEdit() on the original collection. If it fails, I do CancelEdit() on the original collection. Then, when I re-bind the datasource, I again do a BeginEdit().
This works, except that ResetBindings(false) bumps (only) the first collection object's EditLevel by 1, and subsequently give me a "Edit level mismatch in CopyState" (CSLA v3.0 Beta2) exception when I try to do the BeginEdit() on the collection. If I ApplyEdit() on the first object in the collection prior to doing the BeginEdit on the whole collection, everything seems to work... but I don't want to leave it that way. Any suggestions?
I removed the BeginEdits on the collection and tried the CancelEdit on the binding source. Again, it did not recover the item from the DeleteList... the EditLevel is 0 after I assign the collection to the binding source. I'm thinking this is the source of my problem.
Before I get to my test case, I'm re-using the DataGridView to display two prior collections. I notice the first time I assign the first collection to the datasource (and hence the DataGridView), the EditLevel is changed to 1. (this is good) Then, in moving on to the next collection, I do an EndEdit on the datasource, assign it null, and then assign it the second collection, on my way to my test case. At this point, the EditLevel is 0. The same happens when I finally get to my test case collection. So, I end up with a DataGridView that uses a DataSource where the underlying collection has an EditLevel of 0. Which I think is not good, and the reason the CancelEdit on the datasource does not un-do. Am I on the right track?
What is your root object?
If your root is a BB, with a child BLB of children, then you
should never have to call ___Edit() yourself.
If your root is a BLB then you may need to call ___Edit()
yourself, but you must do it BEFORE and AFTER data binding. In other words,
call BeginEdit() before hooking up data binding, and only call CancelEdit() or
ApplyEdit() after you’ve disconnected data binding.
You can see an example of doing this in the BLBTest sample app’s
Form1
code.
Rocky
From: bearntrail [mailto:cslanet@lhotka.net]
Sent: Thursday, June 28, 2007 2:44 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Proper way to handle deletes in a DataGridView?
I removed the BeginEdits on the collection and tried the CancelEdit on the
binding source. Again, it did not recover the item from the DeleteList...
the EditLevel is 0 after I assign the collection to the binding source.
I'm thinking this is the source of my problem.
Before I get to my test case, I'm re-using the DataGridView to
display two prior collections. I notice the first time I assign
the first collection to the datasource (and hence the DataGridView), the
EditLevel is changed to 1. (this is good) Then, in moving on to the next
collection, I do an EndEdit on the datasource, assign it null,
and then assign it the second collection, on my way to my test
case. At this point, the EditLevel is 0. The same happens when
I finally get to my test case collection. So, I end up with a
DataGridView that uses a DataSource where the underlying collection has an
EditLevel of 0. Which I think is not good, and the reason the CancelEdit
on the datasource does not un-do. Am I on the right track?
Copyright (c) Marimer LLC