I have classes such as Address & Client which hold properties.
I have created a ViewModel like so:
public class MyViewModel{
public Address MyAddressObj {get;set;}
public Client MyClientObj {get;set;}
}
Can I bind MyViewModel to the Grid and show the properties of the Address & Client classes. I have already tried and it just creates columns called MyAddressOb & MyClientObj. I would like to specify what properties of the classes are displayed in the grid if possible via code.
Oh, sorry, I misunderstood.
The way it works is that when you bind an object as the DataSource of the grid, the grid checks to see if the object implements IList or IBindingLIst. The items in the list become rows and the properties on those items become columns. If one of the properties returns an IList or an IBindingList, then that property is treated as a child band.
There's no automatic way to break down a single property into multiple child properties. But you could achieve this in any number of ways.
That doesn't really answer the question I have a class which exposes 2 other classes as properties. When I bind to the grid it shows those class properties as 2 columns.
How do I specify the columns I want to appear from the properties of the 2 classes I have in the class I am binding to?
If you want to hide columns in the grid, the best thing to do is to handle the InitializeLayout event and set the hidden property on the columns.
Another option would be to apply the Browsable(false) attribute the properties that you want to hide from DataBinding.