日期:2014-05-18 浏览次数:20901 次
public class Student { private int stuId; public int StuId { get { return stuId; } set { stuId = value; } } private string stuName; public string StuName { get { return stuName; } set { stuName = value; } } private Sex stuSex; public Sex StuSex { set { stuSex = value; }//这里设置成只写 } public Student() { } public Student(int id, string name, Sex stusex) { this.StuId = id; this.StuName = name; this.StuSex = stusex; } //另外增加一个只读属性 public string Sex { get { return stuSex.StuSex; } } } public class Sex { private string stuSex; public string StuSex { get { return stuSex; } set { stuSex = value; } } public Sex() { } public Sex(string sex) { this.StuSex = sex; } } //调用 Student[] student = new Student[] { new Student ( 1, "Hello",new Sex("男") ) , new Student ( 2, "World",new Sex("女")) }; //绑定dgv this.dataGridView1.DataSource = student;