日期:2014-05-18  浏览次数:20901 次

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

------解决方案--------------------
dataPropertyName="sex.title"==================dataPropertyName=sex.title;

这对吗??
------解决方案--------------------
探讨

我也这么写的,不行啊,这好像和网页不同啊

------解决方案--------------------
重点看一下定义类的那两句注释
C# code

     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;