Hello,
In the C# version of the book, on page 491, it shows how to save data when using data binding for Windows Forms.
When I follow that, I get a ValidationException: Object is still being edited and cannot be saved.
Searching this forum, I found that if I call xxxBindingSource.EndEdit(), things go ok.
Is this just missing from the code sample, or am I missing something? I'm new to CSLA, so I'm guessing I'm missing something.
Thanks,
Mike
Hi Brett,
It's actually .ApplyEdit(), not .EndEdit(). Each .BeginEdit() call must have a corresponding .CancelEdit() or .ApplyEdit() call (C# book page 116, under the N-Level Undo heading).
If you're using data binding, the data binding calls .BeginEdit(), so you still need to call .ApplyEdit() even if you didn't call .BeginEdit(), as data binding did it for you.
Mike
Mike,
It actually is EndEdit() - but on the BindingSource. There's an errata on this. It turns out that the code in the book isn't a good model in every case, because data binding (the BindingSource) needs to be in control. In short, you should avoid calling BeginEdit or ApplyEdit directly at all, and rather should work through the BindingSource instead.
It is true that the overall flow must change to accomodate this different model. The Clone() call is still necessary, but must be handled differently. Look at the PTWin\ProjectEdit form in 2.0.1 or higher to see how it needs to work.
Thanks for clearing that up. Apologies for handing out bad advice. I need to print out the errata and stick it in the book.
Mike
Copyright (c) Marimer LLC