【新手】DevExpess的GridView嵌套表格

21 篇文章 0 订阅
8 篇文章 1 订阅

嵌套表格效果图一

嵌套表格效果图一嵌套表格效果图二

嵌套表格效果图二


可视化编辑界面,一个gridControl1(GridControl),下面是MainView(名为gridView_dept的GridView),再添加子层Level1(也是个GridView,名为gridView_Module)


编辑两个GridView的各个Columns,把FieldName字段与数据库表的名称对应好





代码:

        public DataSet ds = new DataSet();
        public DataTable dtModule;
        public DataTable dtDept;
        private void onLoad(object sender, EventArgs e)
        {
            dtDept = BLLUtil.GetTableData(TableField.T_FORM.T_NAME, string.Empty);//父表装进DataTable
            dtModule = BLLUtil.GetTableData(TableField.T_FORM_QUESTION.T_NAME, string.Empty);//子表装进DataTable
            ds.Tables.Add(dtDept);
            ds.Tables.Add(dtModule);
            //下面映射主从关系Add(Level1是名称,会显示在子表的标签处,有文章说这个名称要与子一级的GridView名称相同,我试过不同也可以,比如这里写Level2也没问题))
            //第二个参数是主表的对应键
            //第三个参数是子表的对应键
            ds.Relations.Add("Level1",ds.Tables[TableField.T_FORM.T_NAME].Columns["FORMID"],ds.Tables[TableField.T_FORM_QUESTION.T_NAME].Columns["FORMID"]);
            this.gridControl1.DataSource = ds.Tables[0];
        }



运行就可以了。


P.S.1:ChildGridViewName的属性我没设置。也没问题。


P.S.2:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.

这个错误惭愧了,没有把DataSet  ds初始化就Add。


P.S.3:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ArgumentException: This constraint cannot be enabled as not all values have corresponding parent values.

这个错误是数据问题,这个嵌套表格对于数据要求是“只许父无子,不能子无父”,如果子表的映射键值,在父表中没有,则报此错误。








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值