我如何在 telerik radgridview 的顶层显示多个独立模板
how can i show multiple indenepdent template in top level of telerik radgridview
hello:
i want add multiple template to radgridview and show templates in tabbed style ,
my templates is independent and no relation to each other,
when i add templates to masterTemplate and set datasource of my templates,
datagrid is show empty grid and templates is not visible.
some tried code :
Add Template Section:
GridViewTemplate gvt = new GridViewTemplate();
gvt.AllowDeleteRow = false;
gvt.AllowEditRow = false;
gvt.ShowTotals = true;
gvt.Caption = SubCaption[i];
radResult.MasterTemplate.Templates.Add(gvt);
radResult.Refresh();
设置Indexnumber为模板索引的数据源部分:
radResult.MasterTemplate.Templates[IndexNumber].DataSource = dtl;
radResult.MasterTemplate.Templates[IndexNumber].Refresh();
radResult.Refresh();
我想要的视图是:
RadGridView target view
我该怎么做?
提前致谢
RadGridView 仅通过 MasterGridViewTemplate 提供一个主级别。您可以根据需要将任意数量的子 GridViewTemplates 添加到主级别。此处提供更多信息:https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations
但是,这需要 MasterTemplate 和每个子 GridViewTemplate 之间的关系。
为了从父级别的 RadGridView 中的选项卡式视图的屏幕截图实现您的设计,我可以建议以下方法:
使用单个 RadGridView 实例并使用 load on demand 设置层次结构。为此,有必要为主级别添加一个虚拟行并保持扩展。以下代码片段显示了如何实现它:
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);
}
}
}
- 使用 RadDock or a RadPageView 并根据需要添加任意数量的选项卡 documents/pages。然后,在每个 tab/page 上添加一个单独的 RadGridView 控件并用相关数据填充它。
请随意使用最适合您要求的方法。
hello: i want add multiple template to radgridview and show templates in tabbed style , my templates is independent and no relation to each other, when i add templates to masterTemplate and set datasource of my templates, datagrid is show empty grid and templates is not visible. some tried code : Add Template Section:
GridViewTemplate gvt = new GridViewTemplate();
gvt.AllowDeleteRow = false;
gvt.AllowEditRow = false;
gvt.ShowTotals = true;
gvt.Caption = SubCaption[i];
radResult.MasterTemplate.Templates.Add(gvt);
radResult.Refresh();
设置Indexnumber为模板索引的数据源部分:
radResult.MasterTemplate.Templates[IndexNumber].DataSource = dtl;
radResult.MasterTemplate.Templates[IndexNumber].Refresh();
radResult.Refresh();
我想要的视图是: RadGridView target view
我该怎么做?
提前致谢
RadGridView 仅通过 MasterGridViewTemplate 提供一个主级别。您可以根据需要将任意数量的子 GridViewTemplates 添加到主级别。此处提供更多信息:https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations
但是,这需要 MasterTemplate 和每个子 GridViewTemplate 之间的关系。
为了从父级别的 RadGridView 中的选项卡式视图的屏幕截图实现您的设计,我可以建议以下方法:
使用单个 RadGridView 实例并使用 load on demand 设置层次结构。为此,有必要为主级别添加一个虚拟行并保持扩展。以下代码片段显示了如何实现它:
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); } } }
- 使用 RadDock or a RadPageView 并根据需要添加任意数量的选项卡 documents/pages。然后,在每个 tab/page 上添加一个单独的 RadGridView 控件并用相关数据填充它。
请随意使用最适合您要求的方法。