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();
Set Data Source Section that Indexnumber is template index:
radResult.MasterTemplate.Templates[IndexNumber].DataSource = dtl;
radResult.MasterTemplate.Templates[IndexNumber].Refresh();
radResult.Refresh();
my desired View is : RadGridView target view
how must i do that?
thanks advance
RadGridView offers only one master level via the MasterGridViewTemplate. You can add as many child GridViewTemplates to the master level as you need. More information is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/hierarchy-of-one-to-many-relations
However, this requires a relation between the MasterTemplate and each of the child GridViewTemplates.
In order to achieve your design from the screenshot for a tabbed view in RadGridView on the parent level, I can suggest the following approaches:
Use a single RadGridView instance and set up a hierarchy with load on demand. For this purpose, it would be necessary to add a dummy row for the master level and keep it expanded. The following code snippet shows how to achieve it:
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);
}
}
}
Feel free to use this approach which suits your requirements best.