C# devExpress GridControl 行中行 子行 多级行
在工作中经常会碰到需要做行中行,多级行的情况,不熟的情况下,我也只能试着实现.
命名空间
using DevExpress.XtraEditors.Repository; using System.Data.SqlClient;
实现代码
一下实现的也只是一个demo,大家不要拘泥于数据
DB db = new DB(); DataSet ds = new System.Data.DataSet(); SqlCommand comm2 = new SqlCommand(sql, db.getSqlConnection()); //db.getSqlConnection() 返回一个sqlConnection 对象 SqlCommand comm3 = new SqlCommand(sql1, db.getSqlConnection()); SqlCommand comm4 = new SqlCommand(sql2, db.getSqlConnection()); SqlDataAdapter da2 = new SqlDataAdapter(comm2); SqlDataAdapter da3 = new SqlDataAdapter(comm3); SqlDataAdapter da4 = new SqlDataAdapter(comm3); da2.Fill(ds,"emp"); da3.Fill(ds,"job"); da4.Fill(ds,"re"); this.treeListLookUpEdit1TreeList.DataSource = ds; DataColumn parentColumn = ds.Tables["emp"].Columns["empNum"]; DataColumn childColumn = ds.Tables["job"].Columns["empNum"]; DataColumn secondChild = ds.Tables["re"].Columns["empNum"]; DataRelation relCustOrder; relCustOrder = new DataRelation("对应工作", parentColumn, childColumn); DataRelation job; job = new DataRelation("部门调整", childColumn, secondChild); ds.Relations.Add(relCustOrder); ds.Relations.Add(job); this.gridControl1.DataSource = ds.Tables["emp"];实现效果如下: