databinding to 1:1 related Business objects

databinding to 1:1 related Business objects

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


pillesoft posted on Friday, April 25, 2008

Dear All,

i have a BO.
this BO has some properties like Code, Name, etc.
there is a property which type is another BO. so these two BOs are 1:1 relations. this is the Unit object, which has Code property too.

in a winform there are the parent BO textboxes, each are bounded to the appropriate property.
      this.codeTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.plantUnitBindingSource, "Code", true));

the Unit text box is bounded to Unit.Code.
      this.codeTextBox2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.plantUnitBindingSource, "Unit.Code", true));

the problem is when i enter something to the first code textbox, the same text appearing in the Unit text box too.
what is the problem?

if you need some more info let me know, this is a kind of blocking for me, so please give some hint.

Ivan

ajj3085 replied on Friday, April 25, 2008

You need a seperate BindingSource for the Unit child BO.  The datasource should be the plantUnitBindingSource, the DataMember should be Unit.  Then codeTextBox2 should bind to unitBindingSource, with Code as the DataMember.

FatPigeon replied on Friday, April 25, 2008

Ivan,

I have just tried out what you are suggesting and it works fine for me. In my case I have a property called description in a customer parent BO and a description field in a one to one customerAddress child object, I have set the binding in code in the way you describe and it works.

How about doing a bit more checking before changing your approach?

Regards,

Patrick

pillesoft replied on Monday, April 28, 2008

Dear Patrick,

i'm really confused now.
in one of my forms the databinding works; even if i don't create seperate bindingsource. i have Code, and Name textbox for the child object
but
on another form the entered string into the parent object code property appears in the child object code property.

i have another problem when i try to display this 1:1 related objects into a grid. how can i tell c# to display the child object code property in a column. as i know i can only bind one databinding to a grid

sorry to write this in this mail list, may be it is not really csla problem.
what shall i do?
can you give me some good tutorial about object data binding? there are many, but mainly there are bounded to a database fields.

thank you

Ivan

FatPigeon replied on Monday, April 28, 2008

Ivan

The only thing I can suggest about your ‘parent object code property appears in the child object code property’ issue is that there must be some mix up with how you are doing your data binding on this form. When I get confused I often try just recoding the form from scratch. As you know from the form that does not confuse the two, this technique does work.

I have not found a way to bind 1:1 child object properties to columns in a grid when the grid is bound to the parent’s binding source. The way I would try to get around this is to surface the child object properties as properties in the parent. In other words, have a parent property that wraps the 1:1 child property. This parent property can be bound in the normal way.

I have not come across a really good technical discussion on windows forms data binding. I have learnt as much from Rocky’s books as anywhere else. Please let me know if you find one.

Regards,

Patrick

ErikPhilips replied on Monday, April 28, 2008

Not knowing why there is a 1:1 BO relationship, why is it not possible to create a singal BO that handles all the data in a single object?

Copyright (c) Marimer LLC