Child Template Clickable but unable to insert or add data into it (Unbound Radgridview)

1 Answer 135 Views
GridView
Leenah
Top achievements
Rank 1
Iron
Leenah asked on 31 Mar 2022, 05:37 AM

 

Hello,

I have an unbound hierarchical radgridview that has a parent template and two child templates. The master templates work fine, I can insert, type or paste data. But in the child template, I cannot add any data or rows. It remains blank. Can you tell me what I am doing wrong?

My code are below.

Thank you in advance.

 

private void TestForm_Load(object sender, EventArgs e)
        {            
         // Setup the Master Template
                RadGrid.MasterTemplate.Columns.Add          (new GridViewTextBoxColumn("Name"));
                RadGrid.MasterTemplate.Columns.Add          (new GridViewTextBoxColumn("Description"));
                RadGrid.MasterTemplate.Columns.Add          (new GridViewDateTimeColumn("Date"));
                RadGrid.MasterTemplate.Columns.Add          (new GridViewDecimalColumn ("Value"));
                RadGrid.MasterTemplate.Columns.Add          (new GridViewTextBoxColumn("Status"));
                RadGrid.MasterTemplate.Columns.Add          (new GridViewTextBoxColumn("NameCode"));
                RadGrid.MasterTemplate.Columns.Add          (new GridViewTextBoxColumn("Event"));

                RadGrid.AllowAddNewRow                              = true;
                RadGrid.AutoGenerateHierarchy                     = true;
                RadGrid.AutoSizeColumnsMode                      = GridViewAutoSizeColumnsMode.Fill;

                //Setup Child Template
                GridViewTemplate Childtemplate                       = new GridViewTemplate();
                RadGrid.MasterTemplate.Templates.Add         (Childtemplate );
                Childtemplate.AllowAddNewRow                         = true;
                Childtemplate.AutoSizeColumnsMode                 = GridViewAutoSizeColumnsMode.Fill;

                Childtemplate.Columns.Add                                (new GridViewTextBoxColumn  ("Name"));
                Childtemplate.Columns.Add                               (new GridViewTextBoxColumn  ("Description"));


                //Relation between Parent & child
                GridViewRelation relation                            = new GridViewRelation(RadGrid.MasterTemplate);
                relation.ParentTemplate                              = RadGrid.MasterTemplate;
                relation.ChildTemplate                               = Childtemplate;

                relation.ParentColumnNames.Add("Name");
                relation.ParentColumnNames.Add("Description");
                relation.ParentColumnNames.Add("PtDate");
                relation.ParentColumnNames.Add("Value");
                relation.ParentColumnNames.Add("Status");
                relation.ParentColumnNames.Add("NameCode");
                relation.ParentColumnNames.Add("Event");

                relation.ChildColumnNames.Add ("Name");
                relation.ChildColumnNames.Add ("Description");


                RadGrid.Relations.Add(relation);

 //load data
                LoadUnboundData();

        }

private void LoadUnboundData()
{
 
                using (RadGrid.DeferRefresh())
                    {
                     TestDataSet Processes                              = new TestDataSet();
                
                    using ( RadGrid.DeferRefresh())
                    {
                     GridViewTemplate firstLevelTemplate                        =  RadGrid.MasterTemplate.Templates[0];
 
                        for (int i = 0; i < Processes.AllProcesses.Count; i++)
                        {
                    
                        TestDataSet.AllProcessesRow ProcessRow         = Processes.AllProcesses[i];
                       
                         RadGrid.MasterTemplate.Rows.Add(
                             ProcessRow.Name,
                             ProcessRow .Description, 
                             ProcessRow.Date, 
                             ProcessRow .Value,
                             ProcessRow .Status, 
                             ProcessRow .NameCode,
                             ProcessRow .Event
                                );
                        
                        for (int j = 0; j < Processes.ProcessTasks.Count; j++)
                        {
                         TestDataSet.ProcessTasksRow TasksRow     = Processes.ProcessTasks[j];
                     
                         firstLevelTemplate.Rows.Add(
                             TasksRow.Name,
                             TasksRow.Description
                                );
                        }
                        }                                  
                    }
                }
        }

 

                                                    

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Apr 2022, 08:09 AM

Hello, Leenah,

I have reviewed the provided code snippet. Note that the GridViewRelation is purposed to specify the column from the child level that points to a parent row from the parent level. For example, if you have an ID column in the master level that is a unique identifier of the row and a ParentID column in the child level that specifies the ID of the parent, these two columns are expected to be present in the GridViewRelation, not adding all of the columns like in the code snippet. 

Please have a look at the following tutorial which demonstrates how to properly setun the relation and hierarchy:
https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-programmatically#hierarchical-grid-in-unbound-mode 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Leenah
Top achievements
Rank 1
Iron
commented on 01 Apr 2022, 08:31 AM

Hello Dess, thank you for your response.

 

When I am trying that, and I click on the task name I have an error message" System.NullReferenceException: 'Object reference not set to an instance of an object.' "

 

               relation.ChildTemplate = Childtemplate;

                relation.RelationName = "AllProcesses_ProcessTasks";
                relation.ParentColumnNames.Add("ProcessID");
                relation.ChildColumnNames.Add("ProcessID");

                ProcessTaskGrid.Relations.Add                                       (relation);
Dess | Tech Support Engineer, Principal
Telerik team
commented on 01 Apr 2022, 10:01 AM

Hello, Leenah,

Please ensure that that the ProcessID column is present in the master and child templates. I have prepared a sample project with dummy data for your reference. It is possible to add new rows not only in the master level but also in the child level:

Please give the sample project a try and see how it works for your scenario.

Leenah
Top achievements
Rank 1
Iron
commented on 01 Apr 2022, 07:12 PM | edited

Dear Dess,

Thank you, you are the best!

It sorted out my issue.

Tags
GridView
Asked by
Leenah
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or