public class Customer
{
public int id { get; set; }
public Person CustPerson { get; set; }
public Customer()
{
this.CustPerson = new Person();
}
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
List<Customer> CustomerList=new List<Customer>();
for (int i = 0; i <= 4; i++)
{
Customer cust = new Customer();
cust.id = i;
cust.CustPerson.FirstName = "john" + i.ToString();
cust.CustPerson.LastName = "deo" + i.ToString();
cust.CustPerson.Age = 20 + i;
CustomerList.Add(cust);
}
dataGridView1.DataSource = CustomerList;
}
我希望firstname
, lastname
&age
打印在 中gridview
,但我得到一列,而不是三列,其中包含mynamespace.person
:-(
帮帮我......任何帮助表示赞赏。