Hello everyone!
I use Telerik controls in my project and have faced with the problem:
I need present my data in RadGridView control in hierarchical view.
The parents' rows should have own set of columns. (For example, the top rows' structure is "Id" and "Name").
For each parent row, their children should have own set of columns that different from theirs parents' rows and different from each other.
For example:
child rows that belong to parent1, should have structure - "Id", "ParentId", "Name", "Price", "Count".
child rows that belong to parent2, should have structure - "Id", "ParentId", "Name", "Date".
In addition, children's should present as a tree, and leafs of this tree should reference on itself.
I think relations between parents and children should be made by GridViewRelation type.
Relations between child rows also should be made by GridViewRelation type.
I have prepared simple example (method Init should call insinde form's contructor that has RadGridView (named as grid) on it), that shows this problem:
/// <summary>
/// Initialize data
/// </summary>
private void Init()
{
grid.BeginUpdate();
// Create parents' data:
// 1. Define structure
var parentData = new DataTable();
parentData.Columns.Add("Id");
parentData.Columns.Add("Name");
// 2. Add data
parentData.Rows.Add(1, "Product1");
parentData.Rows.Add(2, "Product2");
parentData.Rows.Add(3, "Product3");
// 3. Assign data source to grid
grid.DataSource = parentData;
#region Create the first child's data
// 1. Define structure
var childData1 = new DataTable();
childData1.Columns.Add("Id");
childData1.Columns.Add("ParentId");
childData1.Columns.Add("Name");
childData1.Columns.Add("Price");
childData1.Columns.Add("Count");
// 2. Add data
childData1.Rows.Add(10, 1, "Product11", 10.99, 10);
childData1.Rows.Add(100, 10, "Product111", 12, 112);
childData1.Rows.Add(101, 10, "Product112", 2, 105);
childData1.Rows.Add(1000, 101, "Product1121", 5, 0);
// 3. Create GridViewTemplate instance
var template1 = new GridViewTemplate();
grid.Templates.Add(template1);
template1.DataSource = childData1;
template1.BestFitColumns();
// 4. Create relation for parent template
var relation1 = new GridViewRelation(grid.MasterTemplate, template1);
relation1.ChildColumnNames.Add("ParentId");
relation1.ParentColumnNames.Add("Id");
grid.Relations.Add(relation1);
// 5. Create relation for self
var selfRelation1 = new GridViewRelation(template1, template1);
selfRelation1.ChildColumnNames.Add("ParentId");
selfRelation1.ParentColumnNames.Add("Id");
grid.Relations.Add(selfRelation1);
#endregion Create the first child's data
#region Create the second child's data
// 1. Define structure
var childData2 = new DataTable();
childData2.Columns.Add("Id");
childData2.Columns.Add("ParentId");
childData2.Columns.Add("Name");
childData2.Columns.Add("GUID");
// 2. Add data
childData2.Rows.Add(11, 2, "Product21", Guid.NewGuid().ToString());
childData2.Rows.Add(110, 11, "Product211", Guid.NewGuid().ToString());
childData2.Rows.Add(1100, 110, "Product2111", Guid.NewGuid().ToString());
childData2.Rows.Add(11000, 1100, "Product21111", Guid.NewGuid().ToString());
// 3. Create GridViewTemplate instance
var template2 = new GridViewTemplate();
grid.Templates.Add(template2);
template2.DataSource = childData2;
template2.BestFitColumns();
// 4. Create relation for parent template
var relation2 = new GridViewRelation(grid.MasterTemplate, template2);
relation2.ChildColumnNames.Add("ParentId");
relation2.ParentColumnNames.Add("Id");
grid.Relations.Add(relation2);
// 5. Create relation for self
var selfRelation2 = new GridViewRelation(template2, template2);
selfRelation2.ChildColumnNames.Add("ParentId");
selfRelation2.ParentColumnNames.Add("Id");
grid.Relations.Add(selfRelation2);
#endregion Create the second child's data
#region Create the third child's data
// 1. Define structure
var childData3 = new DataTable();
childData3.Columns.Add("Id");
childData3.Columns.Add("ParentId");
childData3.Columns.Add("Name");
childData3.Columns.Add("Date");
childData3.Columns.Add("Flag");
// 2. Add data
childData3.Rows.Add(12, 3, "Product13", DateTime.Now, true);
childData3.Rows.Add(120, 12, "Product131", DateTime.Now, false);
childData3.Rows.Add(1200, 120, "Product131", DateTime.Now, false);
childData3.Rows.Add(1201, 120, "Product132", DateTime.Now, true);
// 3. Create GridViewTemplate instance
var template3 = new GridViewTemplate();
grid.Templates.Add(template3);
template3.DataSource = childData3;
template3.BestFitColumns();
// 4. Create relation for parent template
var relation3 = new GridViewRelation(grid.MasterTemplate, template3);
relation3.ChildColumnNames.Add("ParentId");
relation3.ParentColumnNames.Add("Id");
grid.Relations.Add(relation3);
// 5. Create relation for self
var selfRelation3 = new GridViewRelation(template3, template3);
selfRelation3.ChildColumnNames.Add("ParentId");
selfRelation3.ParentColumnNames.Add("Id");
grid.Relations.Add(selfRelation3);
#endregion Create the third child's data
grid.BestFitColumns();
grid.EndUpdate();
}
I have attached file "Example.jpeg" that illustrates the view that i want.
Can RadGridView present data as I need?!
The result that I get after Init() calling is incorrect.
There are some tabs in children grids named as "table"...
Can you give me advice what i do wrong? What can i do to achieve the desired result?
I hope you understand my problem.
Thanks a lot!
P.S.: Telerik's version is 2011.3.11.1116