Mutliple Binding Sources, One object? Can CSLA help with this?

Mutliple Binding Sources, One object? Can CSLA help with this?

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


awbacker posted on Wednesday, July 30, 2008

Posting here as a last resort, since all experimenting has shown that this won't work.  I'm hoping there is something in CSLA, BindingSourceRefresh, or 3.6 that might make this kind of scenario possible. 

I have a wizard like process where 3+ different user controls are shown in succession.  Each one needs to bind to the same object (which is passed in).   I have a function that will call BeginEdit if the edit level is > 0, which I have tried using, before it binds to the datasource... so... 

To forestall questions.. I have tried not calling BeginEdit(), but source2 won't elevate the edit level if x is still bound to source1.  I have tried suspend/resume binding, tried unbinding before going to the next step, and a bunch of other little tweaks =)  I've put my time in on this one :(

BindWithBegin( source, obj ) {
    if (obj.editLevel > 0) obj.BeginEdit(); source.DataSource=obj;
}
x.Name = "start";
BindWithBegin( source1, x );
x.Name = "after 1";
BindWithBegin( source2, x);
x.Name = "after 2";
BindWithBegin( source3, x);
x.Name = "after 3";
UnbindBindingSource( source3, false );
-- x.Name should = "after 2"
UnbindBindingSource( source2, false );
-- x.Name should = "after 1"

I have tried unbinding in any way possible, but when I completely unbind and then bind to a new source the EditLevel increases.  This is fine, except that it makes re-binding when going *backwards* in the process impossible, since everything gets corn-fused and undo doesn't work any more. 

Any ideas on this, or am I just off my rocker? 

//Andrew

RockfordLhotka replied on Wednesday, July 30, 2008

The rule is that if the object is bound to a bindingsource it will have an elevated edit level. That's inescapable because that's how the bindingsource works.

(technically it IS escapable, because in 3.5 and higher you can disable IEditableObject entirely, so the bindingsource's calls will have no effect)

But it should work in a wizard scenario if the current panel completely unbinds AND gets the edit level to 0 before allowing the next (or previous) panel to bind to the object.

Copyright (c) Marimer LLC