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

Add row in a hierarchy structure

2 Answers 483 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cristina
Top achievements
Rank 1
Cristina asked on 18 Jun 2020, 04:29 PM

I have a radgridview element where I need to programmatically insert a new row into the child structure of a certain parent row. The behavior would be the same as if I add a row from the add new row (UserAddNewRow). The final result should be equivalent to the row 'NEW ROW' in the attached image.

Thank you.

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Jun 2020, 10:08 AM
Hello, Cristina,  

According to the provided information, it is not clear enough whether you are using RadGridView in bound or unbound mode and how exactly the hierarchy is set up. Could you please elaborate?

Without knowing the exact setup, I can give you only general suggestions how to add a new row to the child level. 

If you set the DataSource property (bound mode) for each GridViewTemplate (master level and child level), in order to add a new record for the child template, it is necessary to add a new record to the DataSource collection that is being applied to the child GridViewTemplate. Since there is a relation (GridViewRelation) between the two GridViewTemplates indicating the child ID and the parent ID, it is important to specify the proper parent ID for the new record. Thus, the hierarchy row will be added to the respective parent row.  A sample approach how the hierarchy is setup in this case is available in the "Setting the hierarchical grid in bound mode" section in the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-programmatically 

If you use unbound mode and you add the rows directly to the Rows collection of the respective GridViewTemplate, it is just necessary to add a new row which cell's value for the parent ID points to the desired parent row. A sample approach for this approach is demonstrated in the "Hierarchical Grid in Unbound mode" section in the above referred article.

However, if you are still experiencing any further difficulties, it would be greatly appreciated if you can give us some more details about the precise case. A sample code snippet how you setup and populate the grid with hierarchical data would be greatly appreciated. Thus, we would get better understanding of the precise case and think about a suitable solution.

I hope this information helps. If you need any further assistance regarding the Telerik UI for WinForms suite please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Cristina
Top achievements
Rank 1
answered on 02 Jul 2020, 04:43 PM
Thank you very much for the detailed answer. It has solved the problem for me.
Tags
GridView
Asked by
Cristina
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Cristina
Top achievements
Rank 1
Share this question
or