CancelEdit() problem with Children

CancelEdit() problem with Children

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


rob.polak posted on Thursday, February 26, 2009

Okay so I will give you a breif explanation of our object model.  We have a root class Parameter which contains a List of ParameterAttributes

CSLA Version -> 3.0.4.0
Root Class -> Parameter
Editable Child List -> ParameterAttribute List
Editable Child Class -> ParameterAttribute

So we are using DataBinding on a WinForm(C#) application for Editing these Parameters.  What I am seeing is that child objects are not being removed from the ParameterAttributeList when CancelEdit() is being called.  For example:

ParameterAttributes Before CancelEdit()
[0]       {1223}
[1]       {-2}               <- New Object

ParameterAttributes After CancelEdit()
[0]       {1223}
[1]       {-2}               <- New Object

As you can see it appears that the new objects are still persisting after the CancelEdit().  What would cause this type of issue?

rob.polak replied on Friday, February 27, 2009

Bump.. Anyone?

lianglovexp replied on Monday, March 16, 2009

At the parentObject,you can override AddNewCore methon like this:

protected override object AddNewCore()
      {

            User u = User.NewUser(string.Empty);
            //fault
            //this.Items.Add(u);

            //corrct
            this.Add(u);

            return u;
        }

rsbaker0 replied on Tuesday, March 17, 2009

Another possibility is that the object is still bound to the UI when you called CancelEdit. If you are explicitly unbinding using the RebindUI or similar pattern frequently discussed here, then this would not be the case, but otherwise CSLA may not cascade the undo calls to child objects if the internal BindingEdit flag set via the IEditableObject interface calls indicates it is still bound.

Copyright (c) Marimer LLC