110,539
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt = GetTable("select * from tree") //这里是获得表的内容
Dim dv As DataView = dt.DefaultView
dv.RowFilter = "parentid='0'"
For Each row As DataRowView In dv
Dim nd As New TreeNode(row("text"))
nd.Tag = row("id")
tree.Nodes.Add(nd)
Next
End Sub
Private Sub tree_AfterExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tree.AfterExpand
LoadNodes(e.Node)
End Sub
Private Sub tree_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tree.MouseDown
Dim ndTemp As TreeNode
ndTemp = tree.GetNodeAt(e.Location)
If Not ndTemp Is Nothing Then
LoadNodes(ndTemp)
ndTemp.Expand()
End If
End Sub
Private Sub LoadNodes(ByVal node As TreeNode)
If Not node Is Nothing Then
Dim dv As DataView
dv = dt.DefaultView
dv.RowFilter = "parentid='" + node.Tag.ToString() + "'"
For Each row As DataRowView In dv
Dim nd As New TreeNode(row("text"))
nd.Tag = row("id")
node.Nodes.Add(nd)
Next
End If
End Sub