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

RadTreeView with recursive table

2 Answers 158 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Javier
Top achievements
Rank 1
Javier asked on 16 Mar 2018, 05:57 PM
Hello! I am trying to upload a beam from a recursive table with the following fields:
ID; NAME; ID_FK; TYPE;
1;   CARLOS NULL  0
2;    PETER   NULL  0
3;    JHON     1          1
4;    MARY     1          1

Now I would like it to be loaded according to the relationship, how could I do it?

2 Answers, 1 is accepted

Sort by
1
Arun
Top achievements
Rank 2
Iron
answered on 30 Jun 2021, 01:51 PM

Private Function GetTreeData() As DataTable
        Dim dt As New DataTable()
        Dim dc As New DataColumn()

        dc.ColumnName = "_ID"
        dc.DataType = GetType(Integer)
        dt.Columns.Add(dc)

        Dim dc1 As New DataColumn()
        dc1.ColumnName = "_Name"
        dc1.DataType = GetType(String)
        dt.Columns.Add(dc1)

        Dim dc2 As New DataColumn()
        dc2.ColumnName = "_ParentID"
        dc2.DataType = GetType(Integer)
        dt.Columns.Add(dc2)

        Dim dr As DataRow

        Dim SqlClass As New SQLSERVER 'User defined Class to fetch data from DB
        Dim Reader = SqlClass.selectData("Select * from tbl_GroupCategory")
        If Reader IsNot Nothing Then
            With Reader
                If .HasRows Then
                    While .Read
                        dr = dt.NewRow()
                        dr(0) = .Item("_ID")
                        dr(1) = .Item("_Name").ToString
                        dr(2) = .Item("_ParentID")
                        dt.Rows.Add(dr)
                    End While
                End If
            End With
        End If
        Return dt
    End Function
Private Sub Load_Tree()
        With radTrvDetails
            .DisplayMember = "_Name" 
            .ParentMember = "_ParentID"
            .ValueMember = "_ID"
            .ChildMember = "_ID"
            .DataSource = Me.GetTreeData()
        End With
    End Sub
Hope this will help
0
Nadya | Tech Support Engineer
Telerik team
answered on 02 Jul 2021, 12:15 PM

Hello, Javier,

Considering the provided information it seems that you need to bind RadTreeView based on a parent-child relationship. In this case, I could suggest binding to self-reference data where you should set the ParentMember and ChildMember properties to the respective fields in the data source. Please refer to the following documentation article where a similar approach is described: https://docs.telerik.com/devtools/winforms/controls/treeview/data-binding/binding-to-self-referencing-data 

@ Arun, thank you for your suggestion.

I hope this information helps. Should you have further questions do not hesitate to contact us.

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

Tags
Treeview
Asked by
Javier
Top achievements
Rank 1
Answers by
Arun
Top achievements
Rank 2
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or