Adding child rows to a hierarchical grid.

2 Answers 249 Views
GridView
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Ian asked on 21 Oct 2022, 10:17 AM

I'm following the example from   https://www.telerik.com/forums/object-bound-hierarchy#711007, which describes how to create an object-based hierarchy. An excellent example.

I'm now trying to modify that example to look how I want, and I've done everything apart from the critical bit - adding the row of 'child' data.

For a normal row, I would do:

 Dim gvdi As New GridViewDataRowInfo(myGrid.MasterView)
        With gvdi
            .Cells("name").Value = t.name
            .Cells("status").Value = t.status
            .Tag = t '...plus any other columns I need

        End With

The example uses the simpler constructor for a new child row, like:

                childTemplate.Rows.Add(t.id, tt.name, tt.status) '....where 't' is my object.

This also works fine

But now I'd like to use the first style of constructor for the child row, and I can't work out how to do it.

When I use the first bit of code, the runtime complains that it's not a GridViewHierarchyRowInfo, so I changed it to be:

 Dim gvdi As New GridViewHierarchyRowInfo(myGrid.MasterView)
               'With gvdi
                   .Cells("name").Value = tt.name
                   .Cells("status").Value = tt.status
                   .Tag = tt
               End With

...and that doesn't work either. Is it the GridViewHierarchyRowInfo(myGrid.MasterView) which is wrong?

Any ideas?

Thanks

2 Answers, 1 is accepted

Sort by
0
Maria
Telerik team
answered on 25 Oct 2022, 01:18 PM

Hi Ian,

Thank you for the code snippets.

First, I want to point out that the example you are looking at is quite old. According to the code snippets you have sent I assume that you are using the RadGridView control in unbound mode. I am sending you a link to our documentation where you can check the Hierarchical Grid in the Unbound Mode section and more specifically the LoadUnboundData method where you can see how to add child rows to the hierarchical grid.

Here is the link to our documentation: 

https://docs.telerik.com/devtools/winforms/controls/gridview/hierarchical-grid/binding-to-hierarchical-data-programmatically

You have two options whether the RadGridView is in unbound or bound mode. In the link to our documentation, you can find also information about the RadGridView in bound mode and choose which approach is more useful for your implementation.

I hope this information is useful for you.

Give it a try and don't hesitate to write again if you have more questions.

Regards,
Maria
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 25 Oct 2022, 01:31 PM

Thanks - but I get a 404 error with the above link.
0
Maria
Telerik team
answered on 25 Oct 2022, 02:46 PM

Hi Ian,

I am sorry for the inconvenience, we are working on this problem. You can try to open the link another way. You can copy it and put it in the search engine you use. That's how it should work for now until we fixed the hyperlinks. 

Regards,
Maria
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/.

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 28 Nov 2022, 03:25 PM

A much better example -thanks....

...but it also uses the

childTemplate.Rows.Add(t.id, tt.name, tt.status) ...

..style of adding rows, rather than...

Dim gvdi As New GridViewHierarchyRowInfo(myGrid.MasterView)
               With gvdi
                   .Cells("name").Value = tt.name
                   .Cells("status").Value = tt.status
                   .Tag = tt

...(etc)
               End With

...which is what I need.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 29 Nov 2022, 06:51 AM

Hi, Ian,

The GridViewTemplate.Rows.AddNew method adds a new row to the grid template. Then, you can add values to the respective cells:

 Dim r As GridViewRowInfo = childTemplate.Rows.AddNew()
 r.Cells("ColumnName").Value = "value"

I hope this helps.

Ian
Top achievements
Rank 2
Bronze
Iron
Iron
commented on 29 Nov 2022, 09:18 AM

Ah - that seems to work. Thanks!
Tags
GridView
Asked by
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Maria
Telerik team
Share this question
or