datagridview 的datasource为list<userinfo>,而userinfo实体里面有别的实体(sex),所以在页面绑定的时候,dataPropertyName="sex.title",结果页面并没有显示,高手快来

解决方案 »

  1.   

    dataPropertyName="sex.title"==================dataPropertyName=sex.title;这对吗??
      

  2.   

    如果写成dataPropertyName=“sex”,那么就显示这个sex实体信息了,但是我不能显示我指定的title那个属性
      

  3.   

    我试了n种写法,dataPropertyName=“sex<title>”,dataPropertyName=“sex{title}”...没有一次成功
      

  4.   

    重点看一下定义类的那两句注释     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;