Windows Forms data binding bug? (CSLA 3.8.3)

Windows Forms data binding bug? (CSLA 3.8.3)

Old forum URL:

frankhoffy posted on Tuesday, July 20, 2010

I've encountered what appears to be a bug with the CancelEdit functionality in a Windows Forms app.

Steps to reproduce:

  1. Launch Project Tracker (PTWin) and bring up the project edit form (any project will do)
  2. Type some stuff into the description field
  3. Shut down your SQL server instance
  4. Hit the apply button (this will cause an exception from SQL server)
  5. Restart your SQL server instance
  6. Hit the Cancel button.  Nothing happens.  The original text should have been restored for Description at this point.

I've found that when the object is in this state, it has an EditLevel of 0, which is why CancelEdit isn't working.  Any exception thrown from the database layer will cause this same behavior.  I tested this by calling RAISERROR from the stored proc.

Any workarounds would be appreciated.

RockfordLhotka replied on Tuesday, July 20, 2010

That's actually standard behavior.

What happens is this:

  1. The user clicks Save
  2. That means ApplyEdit() is called on the object graph, committing all user changes to the object in memory
  3. The object is then cloned
  4. The clone is then saved
  5. The exception occurs, so the clone is discarded
  6. The UI is left referencing the original object because Save() errors out

If you want different behavior, you'd need to grab a clone of your object graph before the ApplyEdit() call, then catch the exception from Save() and bind the UI to the clone.

frankhoffy replied on Tuesday, July 20, 2010

Very interesting.  Any suggestions for how I can grab the new object instance if I'm using a CslaActionExtender?

frankhoffy replied on Wednesday, August 18, 2010

I think I'm very close but I keep running into an exception.  I'm using CslaActionExtender.  I clone the object in the ObjectSaving event.  I trap the ErrorEncountered event to handle exceptions from the database server.  In that event, I call ResetActionBehaviors using the clone (this is because data bindings are lost when the exception occurs).  When I hit the Cancel button, it works fine on the parent, but the child list collection is giving me an edit level mismatch exception.

Copyright (c) Marimer LLC