How to handle multiple BeginEdit and only one Save()...

How to handle multiple BeginEdit and only one Save()...

Old forum URL:

idroesse posted on Friday, November 05, 2010

Hi guys, just a question for you.  I'm writing a WPF application that use the old MDI concept (one main page with severel detail pages), where I choose my root object (from the main page) and than open the details page.  Every time a detail is open, I do a "BeginEdit" and every time it is closed I do a "ApplyEdit" or "CancelEdit", without executing Save() method.  In my main page, there is a Confirm button (enabled by "IsSavable" property of the root object) and here there is the problem. 

If I press Confirm button (that execute Save() method) how can I force ApplyEdit or CancelEdit in each open detail page before execute Save method? Is there a way to do it or do I need to loop through each open page, ask user if he want to save thus executing ApplyEdit or CancelEdit, and than save root object?


JonnyBee replied on Sunday, November 07, 2010


In an MDI application I would recommend to use BeginEdit/ApplyEdit/CancelEdit on the root object only.

There is no way to determine a sequence of how the form's are being edited and since the user calls Save on the root object - to me it is also the point of Cancel or Apply.

If you should call BeginEdit on the same object in 2 forms you are getting into trouble.



RockfordLhotka replied on Sunday, November 07, 2010

Really, if you allow multiple windows to edit the same object graph, you shouldn't use n-level undo at all. As Jonny says, there's no way to predict the order in which anything will occur, so there's no way to keep any parent-child edit levels in sync.

So unless the entire MDI form represents one root object, it isn't clear to me how you could use the feature at all.

idroesse replied on Monday, November 08, 2010

Thanks guys for the help.  Let me explain better..  My mdi form reppresent only one root object (choosed from a combobox within it). Once a root object is selected I let my user open several detail window.  For example, root object is a Customer and each detail is an invoice.  User open two details (invoice 10/01 and invoce 10/02) and then modify description of each invoices.  Now he can press Ok button (doing ApplyEdit()) or Cancel Button (doing CancelEdit()), but what if he press SaveButton (on MDI form) before close each window?  I was wondering if it's correct to ask him what action do (accept or cancel) in each page,  keeping in mind that I can easily build an ordered list of open windows, and so loop throught it... 


idroesse replied on Monday, November 08, 2010

I forgot... each BeginEdit, ApplyEdit or CancelEdit is made in the root object


RockfordLhotka replied on Monday, November 08, 2010

Let me put this another way.

If more than one active window points to the same object graph (a root or any of its child objects) you will encounter issues.

N-level undo is designed to support modal dialog windows or single window displays. MDI implies several non-modal windows pointing to the same object graph, and in that case you really can't use n-level undo (no calling of BeginEdit/CancelEdit/ApplyEdit per-window).

idroesse replied on Monday, November 08, 2010

Ok, now it's clear! It's monday... Sleep

Thanks a lot, Enrico

Copyright (c) Marimer LLC