I have a datagridview in .NET 3.5 needs to display the following columns :
ID, Name, ID2, Name2
This datagridview is binding as follows :
BindingList source = new BindingList(); source.Add(new Class1 { ID = "1", Name = "Test", Class2Ref = new Class2 { ID2 = "Class2 ID" , Name2 = "Class2 Name"} }); dataGridView1.DataSource = source;
public class Class1 { public string ID { get; set; }
public string Name
{
get;
set;
}
public Class2 Class2Ref
{
get;
set;
}
}
public class Class2
{
public string ID2
{
get;
set;
}
public string Name2 { get; set; } }
The problem is that ID2 and Name2 are not showing any value in the datagridview. I have created the columns in Datagridview at design time and the one corresponding to ID2 and Name2 have been assigned the data property as : Class2Ref.ID2 and Class2Ref.Name2
See, at the UI end, it doesnt matter to User that whether the ID2 and Name2 are properties of Class1 or Class2 but at the Entity design level, it does make a difference. Please tell me how can i show 2 properties in a Datagrid which are not available directly in a class but through a reference.
Thanks Kulvinder Singh