嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
使用devexpress进行三级主从表验证
/// <summary>
/// 创建第一个视图
/// </summary>
private void CreateGridView()
{
var grv = this.gridView1;
var gridControl = this.gridControl1;
//创建从表显示的列
grv.Columns.Clear();
DevExpress.XtraGrid.Columns.GridColumn cl1 = new DevExpress.XtraGrid.Columns.GridColumn();
cl1.FieldName = "ID";
cl1.Caption = "ID";
cl1.Visible = true;
grv.Columns.Add(cl1);
DevExpress.XtraGrid.Columns.GridColumn cl2 = new DevExpress.XtraGrid.Columns.GridColumn();
cl2.FieldName = "Name";
cl2.Caption = "名称";
cl2.Visible = true;
grv.Columns.Add(cl2);
DevExpress.XtraGrid.Columns.GridColumn cl3 = new DevExpress.XtraGrid.Columns.GridColumn();
cl3.FieldName = "Description";
cl3.Caption = "描述内容";
cl3.Visible = true;
grv.Columns.Add(cl3);
grv.OptionsBehavior.ReadOnly = false;
grv.OptionsBehavior.Editable = true;
}
GridView grv2 = null;
GridView grv3 = null;
GridView grv4 = null;
/// <summary>
/// 创建第二个视图
/// </summary>
private void CreateLevelView()
{
var grv = this.gridView1;
var gridControl = this.gridControl1;
//创建一个二级从表的GridView对象
grv2 = new GridView();
grv2.ViewCaption = "记录明细-二级";
grv2.Name = "grv2";
grv2.GridControl = gridControl;
//创建一个三级从表的GridView对象
grv3 = new GridView();
grv3.ViewCaption = "记录明细2-三级";
grv3.Name = "grv3";
grv3.GridControl = gridControl;
//构建GridLevelNode
var topNode = new GridLevelNode();
topNode.LevelTemplate = grv2; //这里是对应的视图
topNode.RelationName = "Detail3List"; //这里对应集合的属性名称
//构建GridLevelNode
var secondNode = new GridLevelNode();
secondNode.LevelTemplate = grv3; //这里是对应的视图
secondNode.RelationName = "Detail2List";//这里对应集合的属性名称
//需要添加节点的层级关系,类似Tree节点处理
topNode.Nodes.Add(secondNode);
//最后添加节点到集合里面
gridControl.LevelTree.Nodes.Add(topNode);
//添加对应的视图集合显示
gridControl.ViewCollection.Clear();
gridControl.ViewCollection.AddRange(new BaseView[] { grv, grv2, grv3 });
//创建从表显示的列
grv2.Columns.Clear();
DevExpress.XtraGrid.Columns.GridColumn cl1 = new DevExpress.XtraGrid.Columns.GridColumn();
cl1.FieldName = "IID";
cl1.Caption = "IID";
cl1.Visible = true;
grv2.Columns.Add(cl1);
DevExpress.XtraGrid.Columns.GridColumn cl2 = new DevExpress.XtraGrid.Columns.GridColumn();
cl2.FieldName = "Name";
cl2.Caption = "名称";
cl2.Visible = true;
grv2.Columns.Add(cl2);
DevExpress.XtraGrid.Columns.GridColumn cl3 = new DevExpress.XtraGrid.Columns.GridColumn();
cl3.FieldName = "Age";
cl3.Caption = "年龄";
cl3.Visible = true;
grv2.Columns.Add(cl3);
DevExpress.XtraGrid.Columns.GridColumn cl4 = new DevExpress.XtraGrid.Columns.GridColumn();
cl4.FieldName = "Sex";
cl4.Caption = "性别";
cl4.Visible = true;
grv2.Columns.Add(cl4);
//创建从表显示的列
grv3.Columns.Clear();
DevExpress.XtraGrid.Columns.GridColumn cl11 = new DevExpress.XtraGrid.Columns.GridColumn();
cl11.FieldName = "ID";
cl11.Caption = "ID";
cl11.Visible = true;
grv3.Columns.Add(cl11);
DevExpress.XtraGrid.Columns.GridColumn cl21 = new DevExpress.XtraGrid.Columns.GridColumn();
cl21.FieldName = "Name";
cl21.Caption = "名称";
cl21.Visible = true;
grv3.Columns.Add(cl21);
DevExpress.XtraGrid.Columns.GridColumn cl31 = new DevExpress.XtraGrid.Columns.GridColumn();
cl31.FieldName = "Description";
cl31.Caption = "描述内容";
cl31.Visible = true;
grv3.Columns.Add(cl31);
//设置非只读、可编辑
grv2.OptionsBehavior.ReadOnly = false;
grv2.OptionsBehavior.Editable = true;
//设置非只读、可编辑
grv3.OptionsBehavior.ReadOnly = false;
grv3.OptionsBehavior.Editable = true;
}