Class with lots of properties

Class with lots of properties

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


ajj3085 posted on Friday, August 04, 2006

Hi,

I have a BO, where I'll have the same set of 15 or so fields repeated three times.. basically the information is SoldTo, ShipTo, and BillTo.. the data elements between those three are the same (Name, adderss, phone, etc).

Is there anything wrong with created a DocumentContact class which contains the 15 properties, and then having a SoldTo, ShipTo, and BillTo properties.. just to keep the parent object a bit cleaner.

Andy

Massong replied on Friday, August 04, 2006

Hi Andy,

 

I use such a contact-class in my order BOs for loading locations, freight rate payers, carriers, and so on. Otherwise I had to repeat the contact properties more than ten times. So it really keeps the object structure clean. But I had one issue: In a collection of such structured objects it was not possible for me to bind properties of the contacts to a Component One grid. Something like “Contact.Name” was not valid as a data source…

 

ajj3085 replied on Friday, August 04, 2006

I've gotten around that; so you have your mainBindingSource object.. create another bindingSource object, and set its data source to mainDataSource, and manually type in the property (which is the class) as the DataMember.  Then you can bind your controls to the secondarybindingSource.  I've done that for other things (where it was clear the class needed to be a child).


Massong replied on Friday, August 04, 2006

Hmm. I use the following method of Component One’s TrueDataGrid to bind my collections to the grid:

Overloads Public Sub SetDataBinding(ByVal dataSource As Object, ByVal dataMember As String, ByVal holdFields As Boolean)

So I call something like that:

MyGrid.SetDataBinding (myCollection, “MyCollectionsPropertie”, True)

I’m not very familiar with data binding in .NET 2.0 yet. I still use the BindField-Helper-method from Rocky’s old book. Sooner or later I must buy a good .NET-2.0-Windows-Forms-book…

ajj3085 replied on Friday, August 04, 2006

The binding source is actually a very easy control to use.  Basically you create a project data source, and set that to be the data source of the binding source.  Then your controls bind to the binding source (and can see the properties available on your object).

When your form loads, you set the data source of the binding source to the actual object when you want to display.  Its very easy, much easier than trying to code it all up.

Copyright (c) Marimer LLC