Binding to Subproperties
I while ago I was asked about binding to objects that contain other objects as properties, and whether there was a way to expose those sub-properties as columns on the grid. At the time, I suggested using OwnerDraw to display the value of the sub-properties in the grid cells, using the column's UserData property to identify which sub-property to bind to. The solution worked but was far from perfect, since it did not support editing or sorting. I did some research and found a much better solution, which I think might be useful to everyone. The solution is based on a custom data source class that extends the standard BindingList
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string Country { get; set; }
}
Creating a BindingList