CancelEdit() - Problem with childs

CancelEdit() - Problem with childs

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


ThomasHepp posted on Monday, October 20, 2008

Hi,

I have a BusinessListBase with BOs. Each of them have a BusinessListBase too. My list is bound to a grid and changes are made in a seperate form.

My Problem: If I call CancelEdit on my BO it doesn't cancel the changes of my child collection. I've debugged the code and I found that in the method "Csla.Core.UndoableBase.UndoChanges(int parentEditLevel)":

if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(field.FieldType))

{
   // this is a child object
   // see if the previous value was empty
   if (state.Contains(GetFieldName(field)))
   {
      // previous value was empty - restore to empty
      field.SetValue(this, null);
   }
   else
   {
   // make sure the variable has a value
   if (value != null)
   {
     // this is a child object, cascade the call.
      if (!_bindingEdit)
         ((Core.
IUndoableObject)value).UndoChanges(this.EditLevel);
   }
}

If that code comes to my child collection "_bindigEdit" is true, altough I called CancelEdit() in my child form.

Now is my question: How can I cancel my modifications so, that the modifications on the childobject are canceld too?

 

RockfordLhotka replied on Monday, October 20, 2008

This is addressed in the Using CSLA .NET 3.0 ebook. Windows Forms data binding is very picky about how the object behaves, and no variation is allowed.

The basic process is this:

  1. BEFORE BINDING to the UI, manually call BeginEdit() on your root object
  2. Bind your object to the UI, let the user do their work
  3. If the user clicks Cancel, UNBIND FROM THE UI, then manually call CancelEdit() on your root object
  4. If the user clicks Save, UNBIND FROM THE UI, then manually call ApplyEdit() on your root

The process of unbinding is a little tricky and must be done exactly as shown in PTWin 3.0.4 or higher, and as described in the ebook. In CSLA .NET 3.6 there's a new CslaActionExtender control (and associated component) to make this process simpler.

Copyright (c) Marimer LLC