有沒有辦法將對象的子屬性綁定到datagridview?這裏是我的代碼:將子屬性綁定到DataGridView
public class Person
{
private string id;
private string name;
private Address homeAddr;
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public Address HomeAddr
{
get { return homeAddr; }
set { homeAddr = value; }
}
}
public class Address
{
private string cityname;
private string postcode;
public string CityName
{
get { return cityname; }
set { cityname = value; }
}
public string PostCode
{
get { return postcode; }
set { postcode = value; }
}
}
而且,當Person類型的對象綁定到datagridview時,我想顯示ID,Name,CityName。請注意,CityName是HomeAddr的一個屬性。
你想CITYNAME和郵編在一列或兩個單獨的列? – BFree 2009-01-13 02:58:21
當然是兩列。 – Graviton 2009-01-13 03:15:43