How to populate tree view for parent child relation in same table
The database structure is:
Id Name ParentId
1 File NULL
2 Open 1
3 Save 1
4 Exit 1
5 Edit NULL
6 Cut 5
7 Copy 5
I want to display the above data in tree view using VB.Net like:
File
----- Open
----- Save
----- Exit
Edit
----- Cut
----- Copy
I am using the database PostgreSQL开发者_C百科.
Sub AddTreeItems(id as Integer, node as TreeNode)
dim s = id.ToString
If id = 0 Then
s = "NULL"
End If
r as new Query("select * from table where parent =" & s)
While r.read()
dim n as new TreeNode(r["name"])
node.Add(n)
AddTreeItems(r["id"],n)
End While
End Sub
The query function is kinda pseudo-code, but I think you get the picture.
精彩评论