如何在同一表中为父子关系填充树视图 [英] How to populate tree view for parent child relation in same table
本文介绍了如何在同一表中为父子关系填充树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据库结构为:
Id Name ParentId
1 File NULL
2 Open 1
3 Save 1
4 Exit 1
5 Edit NULL
6 Cut 5
7 Copy 5
我想使用VB.Net在树状视图中显示以上数据,例如:
I want to display the above data in tree view using VB.Net like:
File
----- Open
----- Save
----- Exit
Edit
----- Cut
----- Copy
我正在使用数据库 PostgreSQL >。
I am using the database PostgreSQL.
推荐答案
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.
这篇关于如何在同一表中为父子关系填充树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文