I would like to bind a column in my DataGridView class to an entry in a 2nd level object in C# using .NET 4.0. For instance:
I have Object A:
public class A
{
public long id;
public B bClass;
}
and Object B
public class B
{
public long id;
public string name;
}
Is there a way to declare a list of class A's as the data source on a DataGridView, yet bind one of the columns to the name attribute in Class B?
I distilled this down a little bit, but hopefully this isn't confusing. Thanks for the Help!
The above solution doesn't work for me. I understood the question more like in this thread: Is it possible to bind complex type properties to a datagrid?
What I did is to implement a class C in the gui-layer that has all the wanted properties in the first level. You can also write a constructor initializing the new class from class A:
public class C
{
public C(A a)
{
Id = a.Id;
Bid = a.bClass.Id;
Bname = a.bClass.Name;
}
public long Id;
public long Bid;
public string Bname;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With