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

How to bind to a RadTreeview

2 Answers 89 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rob Venable
Top achievements
Rank 1
Rob Venable asked on 02 Apr 2010, 05:52 PM
Hi,
I have a query (CTE) that returns the parent child relationship in a dataset and I can bind to an ASP.Net treeview but I want to be able to bind to a RadTreeView. Can anyone help me with the conversion?
Here's my code to bind to a treeview:
 Private Sub InitializeControls()  
 
        '==Get some info from the logged in user  
        Dim oContact As New Contact(UserInstance.ContactID)  
        '== Labels  
        lblDownline.Text = "My Distributor Downline" 
 
        LoadDataSet()  
        '== If it's the root node, SponsorID will be zero so use their contactid  
        Dim parentID As Integer = 0  
        If oContact.SponsorID = 0 Then 
            parentID = UserInstance.ContactID  
        Else 
            parentID = oContact.SponsorID  
        End If 
 
        BuildTree(TreeView1.Nodes, parentID)  
 
    End Sub 
 
    Private Sub LoadDataSet()  
        '==ds is declared at the page level  
        Dim oContacts As New ContactCollection  
        ds = oContacts.GetDownline(UserInstance.ContactID, 8) '==returns a dataset...later would like to return a collection  
 
    End Sub 
 
Private Sub BuildTree(ByVal nodes As TreeNodeCollection, ByVal IntParent As Int32)  
        Dim thisID As Int32  
        Dim thisName As String 
        Dim children As DataRow() = ds.Tables(0).Select("SponsorID='" & IntParent & "'")  
 
        If children.Length = 0 Then 
            Return 
        End If 
        Dim newNode As TreeNode  
        For Each child As DataRow In children  
            thisID = Convert.ToInt32(child.ItemArray(0))  
            thisName = Convert.ToString(child.ItemArray(2))  
            newNode = New TreeNode(thisName, thisID.ToString)  
            nodes.Add(newNode)  
            newNode.ToggleExpandState()  
            BuildTree(newNode.ChildNodes, thisID)  
 
        Next 
    End Sub 

Does anyone know how to do this with a RadTreeView? I almost had it working but the newNode doesn't have a ChildNodes collection.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 05 Apr 2010, 10:58 AM
Hi Rob Venable,

You need to use the Nodes collection instead of ChildNodes (which does not exist).

All the best,
Veskoni
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rob Venable
Top achievements
Rank 1
answered on 05 Apr 2010, 02:12 PM
Thanks Veskoni. I thought I tried this before but it works now.
Tags
TreeView
Asked by
Rob Venable
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Rob Venable
Top achievements
Rank 1
Share this question
or