Errata or my ignorance?

Errata or my ignorance?

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


Michael Hildner posted on Tuesday, June 06, 2006

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

RockfordLhotka replied on Tuesday, June 06, 2006

Nope, it is errata. I just hadn't had time to track down the page number in the book (I'm guessing it might be elsewhere too Sad [:(]).

brettswift replied on Saturday, June 17, 2006

Hey,

I'm getting the same error, and when I call the EndEdit() method I still get the same error.

I'm wondering if it has something to do with the clone not functioning properly ?

Michael Hildner replied on Saturday, June 17, 2006

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

RockfordLhotka replied on Sunday, June 18, 2006

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.

Michael Hildner replied on Tuesday, June 20, 2006

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