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

DEV gridControl 如何样自动更改列数据

2013-02-25 
DEV gridControl 怎么样自动更改列数据数据表 USER 中存放部门信息为部门的编号,在通过数据绑定时显示出来

DEV gridControl 怎么样自动更改列数据
数据表 USER 中存放部门信息为部门的编号,在通过数据绑定时显示出来的数据也是编号,有什么方法可以显示为部门名称而不是编号?
员工信息和部门列表  分别放在两个List<User>和List<Department>中,

 public class User
    {
        public int ID { get; set; }
        public string UserID { get; set; }
        public string Name { get; set; }
        public int Sex { get; set; }
        public DateTime Birth { get; set; }
        public string IDNumber { get; set; }
        public string Address { get; set; }
        public string Nativeplace { get; set; }
        public string Nation { get; set; }
        public string Domicile { get; set; }
        public string Telephone { get; set; }
        public string Email { get; set; }
        public int Marriage { get; set; }
        public string Education { get; set; }
        public string School { get; set; }
        public DateTime GraduationDate { get; set; }
        public string Specialty { get; set; }
        public DateTime EntryDate { get; set; }
        public Department Department { get; set; }
        public string Duties { get; set; }
        public DateTime Departure { get; set; }
        public string Password { get; set; }
        public int onjob { get; set; }
        public int UserType { get; set; }

    }


 public class Department
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int SuperiorDeptID { get; set; }
    }



            List<User> userList = new List<User>();
            userList = new UserBLL().UserAll();
            gridControl1.DataSource = userList;


[解决办法]
引用:
自己搞定了


C# code
?



12345678910111213

 private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)         {           ……


我感觉没有必要这么麻烦LZ,看看我的思路:
首先你可以把显示部门名称的那一列的列属性(ColumnEdit)改成LookUpEdit,Name 属性为Lue_Department,下拉式的。
然后绑定数据源,比如:
List<Department> departmentList = new List<Department>();             departmentList = new DepartmentBLL().DepartmentAll(); 
this.Lue_Department.DateSource = departmentList
this.Lue_Department.DisplayMember = "Name";  // 部门名称
this.Lue_Department.ValueMember = "ID";      // 部门编号
最后是设置这一列的属性:
在ColumnEdit 属性下找Columns,添加两列,设置其FileName为ID,Name 可是设置ID列的Visible为False。

热点排行