469,301 Members | 2,278 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,301 developers. It's quick & easy.

How to add Child nodes under Parent nodes of TreeView in VB.NET from SqlServer database

This is my table

ID ChartName ParentLevel
1 Assets 0
2 Liabilities 0
3 Cash 1
4 Bank 1

I am able to retrieve Treeview Parent Node successfully using below code,

Dim Parent1 As TreeNode
Dim Child1 As TreeNode
Try
con.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader '(CommandBehavior.SingleRow)
While reader.Read()
If reader.Item("ParentLevel") = 0 Then
Parent1 = TreeView1.Nodes.Add(reader.Item("ChartName"))
End If
End While
reader.Close()
Finally
End Try

but unable to populate child nodes under the related parent node.
Result in Treeview should be like this...

-Assets
Cash
Bank
+Liabilities

Help will be apricated.
3 Weeks Ago #1
0 4129

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by reandeau | last post: by
2 posts views Thread by thanneman | last post: by
10 posts views Thread by John Rogers | last post: by
2 posts views Thread by arggg | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.