不管有幾層樹狀選單,只要遞迴資料就能結構出一個
這帖連線的部份
被我寫成物件
所以要參考的朋友
只要新增連線的部份大致上就會跑了
'Recursive loop table and structure treeview
'20111128 by Paul H.
'Table
'ParentNo NodeNo ProgText ProgName
' 0 1 app1 frm1
' 0 2 app2 frm2
' 0 3 app3 frm3
' 0 4 app4 frm4
' 2 5 app5 frm5
' 5 6 app6 frm6
' 5 7 app7 frm7
' 7 8 app8 frm8
' 8 9 app9 frm9
' 8 10 app10 frm10
'form zero to be recursive parent and children nodes
'Nodes0 Nodes1 Nodes2 Nodes3 Nodes4
'1
'2------5------6
'3 ------7------8------9
'4 ------10
-----------------------------------------------------------------
Public Class frmRecursiveTreeView
Private Sub frmRecursiveTreeView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "RecursiveTreeView"
Dim myImageList As New ImageList()
With myImageList.Images
.Add(My.Resources.right)
.Add(My.Resources.bullet_red)
End With
With (treeApp)
.ImageList = myImageList
.ImageIndex = 0
.SelectedImageIndex = 1
.Font = New Font("arial", 12, FontStyle.Bold)
End With
End Sub
Sub RecursiveNode(ByVal ParentNo As Integer, ByVal NodesLevel As TreeNode)
Dim DB As New DBworking ' DBworking it's my class
DB.SQLStr = "SELECT ParentNo, ProgNo, ProgText, ISNULL(ProgName, '') AS ProgName FROM dbo.SysAppTree WHERE ParentNo=" & ParentNo
DB.initialConnection(myParametes)
Dim ParentDT As DataTable = DB.ExcuteSQL("MsSQL").Tables(0)
For Each CurrentRow As DataRow In ParentDT.Rows
Dim CurrentNode As TreeNode
Dim NodeText As String = CurrentRow.Item(1) '& " " & CurrentRow.Item(2)
CurrentNode = New TreeNode(NodeText)
NodesLevel.Nodes.Add(CurrentNode)
CurrentNode.Tag = CurrentRow.Item(3)
RecursiveNode(CurrentRow.Item(1), CurrentNode)
Next
End Sub
Private Sub CreateNodes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateNodes.Click
With treeApp
.Nodes.Clear()
.Nodes.Add(New TreeNode("list of function"))
Dim FirstNode As New TreeNode
FirstNode = .Nodes(0)
RecursiveNode(0, FirstNode)
FirstNode.ExpandAll()
End With
End Sub
End Class
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言