MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Grid BeginEdit and ApplyEdit #506

Open CrossSlide opened 6 years ago

CrossSlide commented 6 years ago

I have a grid bound to my Model, a BuinessList object. I have commands that are called when the user adds/deletes a row. When called they do a Model.BeginEdit() and then AddNew or Remove(child) on the Model. I know every BeginEdit() must have a corresponding ApplyEdit() before saving. How do I determine how many times to call ApplyEdit?

Using: WPF, DevExpress GridControl, Mvvm, CSLA ViewModel

CrossSlide commented 6 years ago

Isn't there an EditLevel property?

ajj7060 commented 6 years ago

I believe there is an EditLevel property, but normally you don't need to call BeginEdit or ApplyEdit, the grids should do that for you. I think maybe you need to call EndEdit after you've unbound the BO from the data source.

CrossSlide commented 6 years ago

Is my approach wrong?

(1) A user selects a Customer from a ComboBox in the View. (2) My ComboBox is bound to a AddNewCommand in the ViewModel. (3) My command adds the new customer to the Model (which the DataGrid immediately recognizes).

I'm doing a BeginEdit() before adding the new customer so the user can undo the addition. This all works but when it's time to save I need to apply all the edits. How?

@ajj7060, I'm not unbinding my Model from the DataGrid before I make the changes. Is this needed?

ajj7060 commented 6 years ago

I'm pretty sure in WinForms you do, because otherwise the binding source will end up calling BeginEdit (I think it does multiple times, and only the first is supposed to be honored). Might be the same in WPF too.

In any event though, if you case your object to IUndoableObject you can see the EditLevel property. Just be careful though; the Begin/End/Cancel edit from that interface are only meant to be used from databinding. Use the Begin/Apply defined on BusinessBase for N-Level undo.

CrossSlide commented 6 years ago

Thank you @ajj7060! That clears some things up for me.