I quickly updated my test project
(http://www.lhotka.net/cslacvs/viewvc.cgi/samples/trunk/RootChildGrandchildWinFormTest/)
to use the 3.0.3+ binding technique and I don't see a failure case there. Maybe I'm not doing something right as a user to make it fail. Can you use that as a test to replicate the issue?
RockfordLhotka:I quickly updated my test project
Ross,
We had a similar problem:
We found that if the Current item of bindingsource 2 changed, EndEdit() was not being called automatically on the Current (grandchild) item, leaving it at EditLevel 1. We solved this problem by calling EndEdit() ourselves. I don't know what event we hooked, but I can look that up if you're interested.
Hope this helps!
Cheers,
Herman
McManus:We found that if the Current item of bindingsource 2 changed, EndEdit() was not being called automatically on the Current (grandchild) item, leaving it at EditLevel 1. We solved this problem by calling EndEdit() ourselves. I don't know what event we hooked, but I can look that up if you're interested.
Thanks! That does appear to be the solution.
What a PITA this all turns out to be...
Ross, Rocky,
Apparently, calling grandchildrenBindingSource.EndEdit() in childrenBindingSource_CurrentChanged solved just a part of the problem. This call takes care of the fact that the EditLevel of the "Current" GrandChild item changes from 2 to 1 (which is a good thing!).
But there seems to be another problem: suppose we delete Child2. Just before the object is deleted, the value of BindingEdit is True. After deleting the object, the value of BindingEdit is still True.
Now, when we cancel the deletion, we first Unbind the bindingsources. This results in all objects being at EditLevel 1 (which is a good thing too!). Then CancelEdit() is called on the Root object. As a result, Child2 is added to the ChildList again. Both have an EditLevel of 0.
BUT: The GrandChildList of Child2 (and all its items) have an EditLevel of 1!!! The reason for this is that UndoChanges() wasn't called on the GrandChildList of Child2 ==> the result of BindingEdit having the value True.
When the root object is rebound again, EditLevelMismatchException is thrown.
The same problem occurs in the following sitation:
Note that the deletion of Child2 was confirmed, but canceling a new edit puts the deleted items back in the list again!!
Complex stuff, isn't it?!?!
Cheers,
Herman
Grumble. I sent a response (possible fix) yesterday, but it
appears to have disappeared between me and the forum :(
The solution appears to be in Core.BusinessBase. In the
DeleteChild() method, add a “BindingEdit = false” line right before
the MarkDeleted() call.
Can you test this in your scenarios and see if it does address
the issue? (the EndEdit() call on the grandchild list is still required too)
Rocky
From: tetranz
[mailto:cslanet@lhotka.net]
Sent: Thursday, January 24, 2008 11:28 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] EditLevel problems with WinForms
Thanks Herman. That sounds familiar from my limited testing.
I sat down to have another play with it at home last night and noticed that
Rocky's test application in the svn has changed from the day before and has
some more debugging in it so I think he's looking at it. Good luck Rocky ">I'm sure it's
time consuming at a awkward time and an absolute PITA to debug.
I only have this on one form and the n in n-level undo is never really > 1
for me so for now I've made the cancel button throw away the objects and reload
from the db. That has solved my immediate problem.
Cheers
Ross
RockfordLhotka:Can you test this in your scenarios and see if it does address the issue?
Ross,
What do your BO's look like for your children and grandchildren. I am doing essentially the same thing you are except with an infragistics grid. When I add a child with grandchildren to the grid through code everything is fine. But, when I try to add records on the fly in the grid I get edit level mismatch on the grandchildren.
Did you just follow the same procedures for your grandchildren as you do for child objects?
Ryan
tetranz:Yes, working perfectly. That's good news. I was worried that we might have to change the binding code in the UI forms again.
My real application uses a Janus grid with the children and grandchildren in a hierarchy so there's no grandchild bindingsource and that's working fine as is a more traditional test application I have.
Thanks
RossRockfordLhotka:Can you test this in your scenarios and see if it does address the issue?
Hi Ryanrkelley:Ross,
What do your BO's look like for your children and grandchildren. I am doing essentially the same thing you are except with an infragistics grid. When I add a child with grandchildren to the grid through code everything is fine. But, when I try to add records on the fly in the grid I get edit level mismatch on the grandchildren.
Did you just follow the same procedures for your grandchildren as you do for child objects?
Ryan
Be aware that if you use private backing fields for your child
objects that you’ll have to do all the manual property and event hookups
that were necessary in CSLA 3.0, because you’ll lose all the features of automatic
child management.
Rocky
From: rkelley
[mailto:cslanet@lhotka.net]
Sent: Thursday, May 22, 2008 3:17 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: EditLevel problems with WinForms
I believe that my issue lies in the fact that I am using
managed (propertyinfo) fields for all of my properties including child object.
It looks like if I take my child objects and convert them to private backed
fields then this error will go away. I am in the process of testing this now.
Rocky,
The fix in BusinessBase.DeleteChild, together with the EndEdit() call on the GrandChild object solve the problem.
Forget my remark about confirmed deletions showing up again. It doesn't happen now!
Cheers,
Herman
Good, thanks!!
I’ve checked in that change to 3.0.4 and 3.5 in svn.
Rocky
From: McManus
[mailto:cslanet@lhotka.net]
Sent: Friday, January 25, 2008 7:07 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: EditLevel problems with WinForms
Rocky,
The fix in BusinessBase.DeleteChild, together with the EndEdit() call on the
GrandChild object solve the problem.
Forget my remark about confirmed deletions showing up again. It doesn't
happen now!
Cheers,
Herman
I’m not sure I follow what you are saying?
You have something like:
Person contains AddressList contains Address(*)
You don’t bind Person or AddressList but you do bind an
individual Address?
Or you bind Person, but not AddressList, and then you do bind an
individual Address?
Rocky
From: Cosmin
[mailto:cslanet@lhotka.net]
Sent: Thursday, April 17, 2008 9:58 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: EditLevel problems with WinForms
Hi,
Some more strange behaviour.
What if you have a collection in the root object but you don't bind it to any
bindingsource. The edit level of the first child is 2 and after applying the
changes the level 1(which is wrong) and it breaks next time I begin edit.
To fix it I just bound the collection to a hidden grid and let the binding framework
do the work.
Is this a problem in the UndoableBase class?
Thanks,
Cosmin
Copyright (c) Marimer LLC