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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)