UndoChangesComplete causing an additional Begin Edit....

UndoChangesComplete causing an additional Begin Edit....

Old forum URL: forums.lhotka.net/forums/t/3719.aspx


CSLABound posted on Monday, October 15, 2007

I have a business base class (Incident) that has some attributes as well as child business base lists.  After binding the Incident class to the windows form, I run into the following issue....

If someone edits one of the child lists and cancels, it sets the _bindingEdit to false even though the stateStack is not 0 and my parent object is still bound.

is there a way to change UndoChangesComplete to check if the canceledit() call isn't removing the entire stack, and avoid setting _bindingEdit to false without messing up the framework?

Brian

CSLABound replied on Monday, October 15, 2007

This was the change I made to Business Base method UndoChangesComplete, and all my tests seem to point to it working:

protected override void UndoChangesComplete()

{

if (base.EditLevel < 1) //changed

{ _bindingEdit = false; }//changed

ValidationRules.SetTarget(this);

AddBusinessRules();

OnUnknownPropertyChanged();

base.UndoChangesComplete();

}

It sems to do the trick.  If someone sees something that would cause an issue, please post. 

Thanks,

Brian

ajj3085 replied on Tuesday, October 16, 2007

I'd be careful here.  The reason BeginEdit is called again is because Windows databinding calls CancelEdit immediately followed by BeginEdit again.  There's no way to stop that behavior (short of unbinding the object), its by design. 

CSLABound replied on Tuesday, October 16, 2007

The reason I see it occur in my code is that I explicitly call a CancelEdit because the user is wanting to undo an insert into one of the child lists.  Because of this undo, a call gets made to UndoChangesComplete, and the _bindingEdit gets set to false, and when we go back to the main screen the parent object appears to rebind, causing the stack count to jump to 2 instead of 1, and the save fails when the user hits the save button because the object is still being edited.  This was the only fix I could see that appeared correct.  If the stack of the base parent is at least 1, it's already been bound so I don't want any rebind by .NET to cause the edit level to change.

Would it be better to unbind and rebind the object? 

Brian

ajj3085 replied on Tuesday, October 16, 2007

Well what version of Csla are you using?  There's been some important fixes, so if you're not on 3.0.2, you may want to consider upgrading to see if that resolves the issue.

Copyright (c) Marimer LLC