首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform上datagridview 数据绑定的有关问题

2012-06-11 
winform上datagridview 数据绑定的问题datagridview 的datasource为listuserinfo,而userinfo实体里面有

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("女"))            };//绑定dgvthis.dataGridView1.DataSource = student; 

热点排行