一、绑定DataSet

     1. 创建数据源 DataSet;DataSet中有两张表,并且主表与子表必须建立关联;

             

DataTable dtMaster =new DataTable();
DataTable dtDetail= new DataTable();
dtMaster .Columns.Add("RelationColumn");
dtDetail.Coumns.Add("RelationColumn");
 using (DataSet ds = new DataSet())  
            {  
                ds.Tables.AddRange(new DataTable[] {
                                                   dtMaster .Copy(), 
                                                   dtDetail.Copy() 
                              }); // 创建表关系 DataRelation relation = new DataRelation("detailTable", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0], false); ds.Relations.Add(relation); // 添加 gridControl1.DataSource = ds.Tables[0]; // 指定数据源 }

 2. ui 设置 gridControl 控件;

         gridControl中已有一默认的Gridview1 为MainView 用来显示dtMaster的数据;

         gridControl 添加一个level.在该level中创建 gridView 命名为gvDetial. 用来显示dtDetail的数据;

         修改level的名称,名称必须和数据源中定义的DataRelation的名称一致;gridcontrol 会根据MasterTable的relation来创建并显示detail的数据结构;

         将两个Gridveiw中的添加Column ,并绑定相应数据源表的字段;

1  this.gvTable.OptionsDetail.AllowExpandEmptyDetails = true;
2  this.gvTable.OptionsDetail.ShowDetailTabs = false;
3  this.gvTable.OptionsPrint.ExpandAllDetails = true;
4  this.gvTable.OptionsPrint.PrintDetails = true;
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-05-27
  • 2021-12-16
  • 2021-09-15
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-12-15
相关资源
相似解决方案