Public Function InitTree(ByVal strTable As String, _
ByRef ParentTreeNode As TreeNodeCollection, _
Optional ByRef dsTree As DataSet = Nothing, _
Optional ByVal ParentID As Integer = -1, _
Optional ByVal ParentTable As String = "", _
Optional ByVal ParentItemID As String = "")
Dim collectRows As DataRowCollection = dsTree.Tables(strTable).Rows
Dim collectSubRows As DataRowCollection
Dim nodX As TreeNode
Dim nodeColl As TreeNodeCollection
Dim strSubTable As String
Dim tmpParentTable As String
Dim I, J As Integer
ParentTreeNode.Clear()
TreeViewTrainsport.BeginUpdate()
For I = 0 To collectRows.Count - 1
If collectRows.Item(I).Item("ParentID") = ParentID Or ParentID = -1 Then
nodX = ParentTreeNode.Add(collectRows.Item(I).Item("Name"))
strSubTable = collectRows.Item(I).Item("TableName")
nodX.Tag = strSubTable
Dim collectSubRows As DataRowCollection
Dim nodX As TreeNode
End If
ElseIf collectRows.Item(I).Item("SubItem") Then
InitTree(collectRows.Item(I).Item("SonTable"),nodX.Nodes,dsTree, collectRows.Item(I).Item(strTable & "ID"), ParentTable, ParentItemID)
End If
End If
Application.DoEvents()
Next
TreeViewTrainsport.ExpandAll()
TreeViewTrainsport.SelectedNode = TreeViewTrainsport.Nodes.Item(0).FirstNode
TreeViewTrainsport.EndUpdate()
End Function