WinForms: Binding to a single Child BO / BindingSource

WinForms: Binding to a single Child BO / BindingSource

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


lukky posted on Friday, March 13, 2009

Hi,

Usually, when a BO has a ChildList, you can have 2 BindingSources on the Form, one for the Parent BO, and one for the ChildList. From there you bind your controls to either the Parent BO or the Child BO.

I'm trying to do the same, but with a single Child BO, and the Windows Forms Designer won't let me chose the Child BO through the Parent BindingSouce as it would if it were a ChildList property. What I mean is that the Form Designer will let me chose the Parent BindingSource as the DataSource for the Child BindingSource, but it doesn't show the Child Property in the DataMember list, so I can't setup the Child BindingSource properly. If I manually enter the name of the Child Property, then I get a runtime crash.

The Child Property is declared as follows on the Parent BO:

private static PropertyInfo<Item> ItemProperty = RegisterProperty(new PropertyInfo<Item>("Item", "Item"));

        public Item Item
        {
            get { return GetProperty(ItemProperty); }
            set { SetProperty(ItemProperty, value); }
        }

where Item is a class derived from BusinessBase.

Has anyone come across this before ?

Thanks for any pointers you may have.

JonnyBee replied on Sunday, March 15, 2009

Hi,

WinForms databinding (and WinForms designer) does not understand 1:1 relationships. You must treat these 2 objects as separate datasources and create the second datasource manually in your form. And you can set the child datasource to the child property in your root object.

If you follow Rockys recommendation to "denormalize" your view-model it would all have been  properties on your root object.

/jonnybee

lukky replied on Wednesday, March 18, 2009

Jonny,

Yes, it had started as a single object, but down the road some requirements have changed and I had to split it up, which then of course caused the 1:1 problem.

I guess I got to the right conclusion, cause what you explain with the 2 datasources is exactly what I did Big Smile [:D]

Regards.

JasonG replied on Monday, October 20, 2014

Hello,

I know this is an old topic but I wonder where i can find more information about denormalizing the view-model. 

thanks.

Copyright (c) Marimer LLC