This is a migrated thread and some comments may be shown as answers.

Not standart hierarchical view

3 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 22 Aug 2012, 12:14 PM

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

3 Answers, 1 is accepted

Sort by
0
Denis
Top achievements
Rank 1
answered on 23 Aug 2012, 05:14 PM
Nobody knows? :(
0
Jack
Telerik team
answered on 24 Aug 2012, 02:56 PM
Hi Denis,

Thank you for writing.

When using self referencing hierarchy, RadGridView uses a single self referencing collection to represent all tree levels. So, it is not possible to have different columns for different rows in this view. However, you could achieve similar behavior by using multiple child views, like demonstrated in the GridView >> Hierarchy >> Tabbed Views example from our demo application. When using this view you can hide different tabs conditionally. 

Find further details about RadGridView hierarchy modes in our online documentation.

I hope this helps.

Greetings,
Jack
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Denis
Top achievements
Rank 1
answered on 24 Aug 2012, 03:19 PM
Thanks, Jack!
I will try to use Tabbed Views. )
Tags
GridView
Asked by
Denis
Top achievements
Rank 1
Answers by
Denis
Top achievements
Rank 1
Jack
Telerik team
Share this question
or