BusinessCollectionBase and Undo

BusinessCollectionBase and Undo

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


marioe2000 posted on Monday, September 18, 2006

Ok,

I've searched high and low about this issue and have not found anything satisfactory up to this point.

I have a collection of very simple editable child objects which I'm binding to a devexpress xtragrid. Almost everything works fine. Reading Lhotka's book is my understanding that one has to be able to completely undo all changes made to a collection before it is commited to the db.

How does one handle undo for a BusinessCollectionBase descendant? I'm trying to BeginEdit upon a button click and doing a CancelEdit on another button. In beetwen there will be inserts, modifications and deletions to the collection. I want to be able to undo all and any changes made to the whole collection. At present I'm able to succesfully insert, change, delete records and commit them to the db.

I've placed an Undo button on the same form as my grid and what I get is the undo of a single record not the whole collection as intended. I can see that the grid is calling BeginEdit and CancelEdit anytime I move from record to record on the grid. But my initial BeginEdit should be able to record the initial state of the collection and my manual CancelEdit should restore it.

I've read many threads on searchcsla.com and also here but have not found a simple solution to this seemingly simple issue. Is it a complicated thing? Having read the book it does not seem that it would be very complicated to do.

As far as I can tell this issue has been discussed many times and I would not be bringing it up if I'd found an answer to it; hence my post.

I'm still having to use version 1.52 of the CSLA framework.

Regards,

Mario Estrella

RockfordLhotka replied on Monday, September 18, 2006

You need to be aware of how data binding (the bindingsource control) uses n-level undo, and how you can use undo as well.

When you bind a collection to a grid, the bindingsource control will automatically call BeginEdit and related methods on a per-row basis.

If you want to also have collection-level undo then you need to handle that manually.

Before binding the collection to the bindingsource you need to call BeginEdit on the collection. This will snapshot the whole collection for later undo.

Once you bind the collection to a bindingsource, it called BeginEdit on the active row right away. At any given time, one row will have BeginEdit called on it from the bindingsource.

When you go to cancel or save the form, you must first call CancelEdit or EndEdit on the bindingsource, and then call CancelEdit or ApplyEdit on the collection. The order is important!

marioe2000 replied on Monday, September 18, 2006

Ahhh ... so correct

Thanks Rocky ... you've made my day.

I said it before and I'll say it again:

Thank you Rockford Lhotka for sharing your experience and wisdom. You are a great individual for doing this.

Regards,

 

Copyright (c) Marimer LLC