码迷,mamicode.com
首页 > 其他好文 > 详细

DEV GridView嵌套

时间:2016-09-26 12:58:36      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

   /// <summary>
        /// 绑定主表和明显表到GridView
        /// </summary>
        /// <param name="machineProduct">主表</param>
        /// <param name="configureData">字表</param>
        private void MasterDatailToGridView(DataTable machineProduct, DataTable configureData)
        {
            machineProduct.TableName = "MachineProduct";
            DataSet ds = new DataSet();
            ds.Tables.Add(machineProduct);
            DataTable dtNew = configureData.Clone();
            dtNew.TableName = "AccessoryConfigure";
            foreach (DataRow dr in configureData.Rows)
            {
                object[] arr = dr.ItemArray;
                dtNew.Rows.Add(arr);
            }
            ds.Tables.Add(dtNew);

    //关联字段为GOODS_ID(商品ID)
            DataColumn keyColumn = ds.Tables["MachineProduct"].Columns["GOODS_ID"];
            DataColumn foreignKeyColumn = ds.Tables["AccessoryConfigure"].Columns["GOODS_ID"];
            ds.Relations.Add("商品单位", keyColumn, foreignKeyColumn, false);

            this.gridControl1.DataSource = ds.Tables["MachineProduct"];
         this.gridControl1.ForceInitialize();
            MachineProductGridView.ExpandAllGroups(); // 默认展开分组
        }
        #endregion

技术分享

DEV GridView嵌套

标签:

原文地址:http://www.cnblogs.com/ThreeGrowthPlan/p/5908496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!