Click here to Skip to main content
15,868,056 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
VB
Private Sub TreeViewSample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As DataSet
        Dim DaMain As New SqlDataAdapter("SELECT * FROM Main", con)
        Dim DaSub As New SqlDataAdapter("SELECT * FROM Sub ", con)
        Dim DaChart_Account As New SqlDataAdapter("Select * From Chart_Account", con)
        con.Open()


        ds = New DataSet()
        'con.Open()
        DaMain.Fill(ds, "Main")
        DaSub.Fill(ds, "Sub")
        DaChart_Account.Fill(ds, "Chart_Account")
        'Close the connection to the data store; free up the resources

        'con.Close()

        'Create a data relation object to facilitate the relationship between the Customers and Orders data tables.
        ds.Relations.Add("Main2Sub", ds.Tables("Main").Columns("Main_Code"), ds.Tables("Sub").Columns("Main_Code"))
        ds.Relations.Add("Sub2Chart_Account", ds.Tables("Sub").Columns("Sub_Code"), ds.Tables("Chart_Account").Columns("Sub_Code"))
        '''''''''''''''''''''''
        TreeView1.Nodes.Clear()
        Dim parentrow As DataRow
        Dim ParentTable As DataTable
        ParentTable = ds.Tables("Main")
        For Each parentrow In ParentTable.Rows
            'Dim parentnode As TreeNode
            parentnode = New TreeNode(parentrow.Item("Main_Code").ToString() & " - " & parentrow.Item("Main_Des").ToString())

            TreeView1.Nodes.Add(parentnode)
            ''''populate child'''''
            '''''''''''''''''''''''
            Dim childrow As DataRow
            'Dim childnode As TreeNode
            childnode = New TreeNode()
            For Each childrow In parentrow.GetChildRows("Main2Sub")
                childnode = parentnode.Nodes.Add(childrow("Sub_Code") & " - " & childrow("Sub_Des"))
                childnode.Tag = childrow("Sub_Code")
                ''''populate child2''''
                ''''''''''''''''''''''''''
                Dim childrow2 As DataRow
                'Dim childnode2 As TreeNode
                childnode2 = New TreeNode()
                For Each childrow2 In childrow.GetChildRows("Sub2Chart_Account")
                    childnode2 = childnode.Nodes.Add(childrow2("Acc_Code") & " - " & childrow2("Acc_Des"))

                Next childrow2
                ''''''''''''''''''''''''

            Next childrow
            '''''''''''''''
        Next parentrow

    End Sub
Posted

1 solution

Follow this one...though its in C#, but its understandable....

Binding Data With ‘TreeView’ Control Asp.net 2.0[^]
 
Share this answer
 
Comments
Engr Hammad 19-Nov-14 13:15pm    
But i dont want to go with CSharp. I just need some navigator or command to count and display record to textboxes.
Thanks....
Engr Hammad 19-Nov-14 13:17pm    
This will help me edit sql data which is populated in treeview.
Good for friendly user interface

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900