Winforms 如何在telerik radgridview的顶层显示多个独立模板

Winforms 如何在telerik radgridview的顶层显示多个独立模板,winforms,templates,telerik,radgridview,Winforms,Templates,Telerik,Radgridview,设置Indexnumber为模板索引的数据源节: GridViewTemplate gvt = new GridViewTemplate(); gvt.AllowDeleteRow = false; gvt.AllowEditRow = false; gvt.ShowTotals = true;

设置Indexnumber为模板索引的数据源节:

                            GridViewTemplate gvt = new GridViewTemplate();
                        gvt.AllowDeleteRow = false;
                        gvt.AllowEditRow = false;
                        gvt.ShowTotals = true;
                        gvt.Caption = SubCaption[i];
                        radResult.MasterTemplate.Templates.Add(gvt);
                        radResult.Refresh();
我的看法是:

我必须怎么做?

感谢advance

RadGridView通过MasterGridView模板仅提供一个主控级别。可以根据需要将任意多个子GridViewTemplates添加到主级。有关更多信息,请访问:

但是,这需要主模板和每个子GridViewTemplates之间的关系

为了从父级RadGridView中选项卡式视图的屏幕截图中实现您的设计,我可以建议以下方法:

  • 使用单个RadGridView实例并使用设置层次结构。为此,有必要为主级添加一个虚拟行并保持其扩展。下面的代码片段显示了如何实现它:

                radResult.MasterTemplate.Templates[IndexNumber].DataSource = dtl;
                radResult.MasterTemplate.Templates[IndexNumber].Refresh();
                radResult.Refresh();
    
  • 使用a或a,并根据需要添加尽可能多的选项卡式文档/页面。然后,在每个选项卡/页面上添加一个单独的RadGridView控件,并用相关数据填充它
  • 请随意使用这种最适合您需求的方法

                radResult.MasterTemplate.Templates[IndexNumber].DataSource = dtl;
                radResult.MasterTemplate.Templates[IndexNumber].Refresh();
                radResult.Refresh();
    
         private void RadForm1_Load(object sender, EventArgs e)
     {
         // TODO: This line of code loads data into the 'nwindDataSet.Products' table. You can move, or remove it, as needed.
         this.productsTableAdapter.Fill(this.nwindDataSet.Products);
         // TODO: This line of code loads data into the 'nwindDataSet.Orders' table. You can move, or remove it, as needed.
         this.ordersTableAdapter.Fill(this.nwindDataSet.Orders);
         // TODO: This line of code loads data into the 'nwindDataSet.Categories' table. You can move, or remove it, as needed.
         this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
    
         this.radGridView1.MasterTemplate.Columns.Add("MasterLevel");
         this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    
         this.radGridView1.MasterTemplate.AllowAddNewRow = false;
         this.radGridView1.ShowColumnHeaders = false;
         this.radGridView1.ShowGroupPanel = false;
    
         GridViewTemplate childTemplateCategories = new GridViewTemplate();
         childTemplateCategories.Caption = "Categories";
         foreach (DataColumn col in this.nwindDataSet.Categories.Columns)
         {
             childTemplateCategories.Columns.Add(col.ColumnName);
         }
         childTemplateCategories.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
         this.radGridView1.Templates.Add(childTemplateCategories);
         childTemplateCategories.HierarchyDataProvider = new GridViewEventDataProvider(childTemplateCategories);
    
         GridViewTemplate childTemplateProducts = new GridViewTemplate();
         childTemplateProducts.Caption = "Products";
         foreach (DataColumn col in this.nwindDataSet.Products.Columns)
         {
             childTemplateProducts.Columns.Add(col.ColumnName);
         }
         childTemplateProducts.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
         this.radGridView1.Templates.Add(childTemplateProducts);
         childTemplateProducts.HierarchyDataProvider = new GridViewEventDataProvider(childTemplateProducts);
    
         GridViewTemplate childTemplateOrders = new GridViewTemplate();
         childTemplateOrders.Caption = "Orders";
         foreach (DataColumn col in this.nwindDataSet.Orders.Columns)
         {
             childTemplateOrders.Columns.Add(col.ColumnName);
         }
         childTemplateOrders.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
         this.radGridView1.Templates.Add(childTemplateOrders);
         childTemplateOrders.HierarchyDataProvider = new GridViewEventDataProvider(childTemplateOrders);
    
         this.radGridView1.RowSourceNeeded += new GridViewRowSourceNeededEventHandler(radGridView1_RowSourceNeeded);
    
         this.radGridView1.Rows.Add("Master");
         this.radGridView1.Rows[0].IsExpanded = true; 
     }
    
     private void radGridView1_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
     {
         if (e.Template.Caption == "Categories")
         {
             foreach (DataRow row in this.nwindDataSet.Categories.Rows)
             {
                 GridViewRowInfo r = e.Template.Rows.NewRow();
                 foreach (GridViewCellInfo cell in r.Cells)
                 {
                     cell.Value = row[cell.ColumnInfo.Name];
                 }
                 e.SourceCollection.Add(r);
             }
         }
         else if (e.Template.Caption == "Products")
         {
             foreach (DataRow row in this.nwindDataSet.Products.Rows)
             {
                 GridViewRowInfo r = e.Template.Rows.NewRow();
                 foreach (GridViewCellInfo cell in r.Cells)
                 {
                     cell.Value = row[cell.ColumnInfo.Name];
                 }
                 e.SourceCollection.Add(r);
             }
         }
         else if (e.Template.Caption == "Orders")
         {
             foreach (DataRow row in this.nwindDataSet.Orders.Rows)
             {
                 GridViewRowInfo r = e.Template.Rows.NewRow();
                 foreach (GridViewCellInfo cell in r.Cells)
                 {
                     cell.Value = row[cell.ColumnInfo.Name];
                 }
                 e.SourceCollection.Add(r);
             }
         }
     }