Binding meltdown with 2.1.4

Binding meltdown with 2.1.4

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


DanEssin posted on Monday, April 23, 2007

I'm back to binding after about 6 months. The old apps are working fine.
Now I've got 2.1.4 and (supposedly) the latest CSLA CodeSmith Templates.

I can successfully put a grid (DevExp) and a binding source on a form and get it to populate - but - I can't get it to "add new"

I've set the allownew properties on the binding source, the navigator and the EditableRootList object.

If I siwtch to a MS binding navigator and click the +, it tells me that the EditableChild object has no public constructor.

If someone has a short checklist of things to do to make binding work, I'd appreciate the help.

Thanks,
Dan

tetranz replied on Monday, April 23, 2007

See the remarks here for BindingList.AddNew.

 http://msdn2.microsoft.com/en-us/library/ms132687(VS.80).aspx

You need to either have a public default constructor, which you don't normally have with CSLA, or handle the AddingNew event.

Overwrite OnAddingNew and in it create the new object and add it to the collection.

Cheers
Ross

DanEssin replied on Tuesday, April 24, 2007

Thanks, I'll study it.

Dan

tetranz wrote:

See the remarks here for BindingList.AddNew.

 http://msdn2.microsoft.com/en-us/library/ms132687(VS.80).aspx

You need to either have a public default constructor, which you don't normally have with CSLA, or handle the AddingNew event.

Overwrite OnAddingNew and in it create the new object and add it to the collection.

Cheers
Ross




RockfordLhotka replied on Monday, April 23, 2007

Or even better, in your collection you can override AddNewCore(), where you create a new child, add it to the collection and return a reference to the new object. That, and setting AllowNew to true, is all you should have to do to enable in-place adding of new rows.

DanEssin replied on Tuesday, April 24, 2007

Thanks.

I'll need to study this - especially after I get your reply to the other message so thaat I am sure that I am making the correct choice of base class for each object. (I'm not sure that I'm good enough yet to be able to tell an editable root apart from an editable child or a switchable just by inspecting the code.)

Dan

RockfordLhotka wrote:
Or even better, in your collection you can override AddNewCore(), where you create a new child, add it to the collection and return a reference to the new object. That, and setting AllowNew to true, is all you should have to do to enable in-place adding of new rows.


DCottle replied on Thursday, May 17, 2007

I have one question about this local creation of the objects.  In the SimpleDataPortal.Create method you have a call that marks the object being created as New

MethodCaller.CallMethodIfImplemented(obj, "MarkNew")

Obviously, if I am not using the dataportal this method is not going to get called.  Where would be the best place to mark the object as new when creating in this manner?  Should it go in the override to AddNewCore?

 

Thanks

RockfordLhotka replied on Thursday, May 17, 2007

MarkNew should be called from inside the object itself. Even if you don’t use the data portal, I recommend using a factory method, which can make the call, or your constructor can make the call.

 

Realistically however, the only reason for calling MarkNew is to ensure that IsDirty returns false. So you don’t need to call it on a new object unless you set some properties (thus marking the object as dirty) during its creation.

 

Rocky

 

From: DCottle [mailto:cslanet@lhotka.net]
Sent: Thursday, May 17, 2007 1:15 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Binding meltdown with 2.1.4

 

I have one question about this local creation of the objects.  In the SimpleDataPortal.Create method you have a call that marks the object being created as New

MethodCaller.CallMethodIfImplemented(obj, "MarkNew")

Obviously, if I am not using the dataportal this method is not going to get called.  Where would be the best place to mark the object as new when creating in this manner?  Should it go in the override to AddNewCore?

 

Thanks



No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.1/807 - Release Date: 5/16/2007 6:05 PM


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.1/807 - Release Date: 5/16/2007 6:05 PM

Copyright (c) Marimer LLC