VS2008 and Object Binding Source

VS2008 and Object Binding Source

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


William posted on Saturday, June 14, 2008

Hi,

I am currently using Visual Studio 2008 and CSLA .NET 3.0.4 for my project development. As I tried to bind the object manually using the older approach, e.g. obj.BeginEdit(), control.DataBinding.Add(...), etc. the object's EditLevel seems to be out of control when I invoked form.Validate(). Based on the PTWin example, it looks like that recommended approach to do databinding to business objects is through Object Binding Source. Please advise.

Thanks.

RockfordLhotka replied on Saturday, June 14, 2008

It is possible that the pre-bindingsource approach no longer works. My focus has been entirely on getting things to work with the bindingsource.

You can always turn off the IEditableObject support entirely - that might help.

beerisgood replied on Friday, July 04, 2008

Hello, Mr. Obvious.  Long time listener, first time caller.  :)

I think I just stumbled upon this issue today.  I think my issue is directly related to this.  In my BindUI procedure I have these 2 lines of code, as they appear in the Project Tracker sample:

_customer.BeginEdit();

customerBindingSource.DataSource = _customer;

Both of these lines cause the UndoableBase object to fire the CopyStateComplete() event, therefore I'm getting it twice.  I also noticed that the AcceptChangesComplete() event is also fired twice. 

Are you saying that I should no longer call BeginEdit, ApplyEdit and CancelEdit on my business object if it is bound to a bindingsource?

RockfordLhotka replied on Saturday, July 05, 2008

This is covered in the Using CSLA .NET 3.0 ebook chapter on Windows Forms.

 

If you want a top-level Cancel button that resets the form to its original values, then you need to call BeginEdit() before binding the object, and then call CancelEdit() or ApplyEdit() after unbinding the object.

 

In between those calls, data binding will also call the *Edit() methods – probably many, many times.

 

If you don’t have a top-level Cancel button on your form, then you should never manually call *Edit() except in the helper method to unbind the object(s) from the bindingsource.

 

Rocky

 

Copyright (c) Marimer LLC