About UnBindDataSource

About UnBindDataSource

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


FrankM posted on Friday, December 19, 2008

New book 2008 page 304,
So how do you save an object? You must first unbind it; you need to disconnect it from the BindingSource.

I couldn't find the explanation for why do I must unBind it. If we don't implement NLevel Undo, do we still need to do unBind when saving?

ajj3085 replied on Friday, December 19, 2008

Databinding will still call BeginEdit, CancelEdit, and EndEdit for you, which in turn is implemented using N-level undo.  So if you use data binding, you need to unbind it and call AcceptChanges to set the EditLevel back to 0 before you can save.

FrankM replied on Friday, December 19, 2008

I don't get it. We don't want N-Level undo. And so far our app don't have any unbinding code, no problem yet.

We do need call AppyEdit() before saving, but what's point for unbinding except for undo purpose.

ajj3085 replied on Friday, December 19, 2008

Well, you can disable IEditableObject interactions, but that will break databinding.  Your users expect a form to act a certain way; Csla implements the proper behavior for you.

I think I gave the wrong advice before; don't call ApplyEdit on the BO, call EndEdit on your BindingSource control. 

Basically, if you want to use databinding, you MUST play by databinding rules.  That means you'll have to follow the pattern in the PTracker sample.  The fact that your application seems to be behavior properly now is just luck.

Or, as I said, you can disable IEditableObject, but then it's up to you to perform the required behavior, or your grid wont' cancel changes when users hit ESC, or try to back out of other changes.

Copyright (c) Marimer LLC