正在学习范例文件“会计科目”如何建立目录树,但对其中两个窗体的 AfterLoade 事件代码不甚理解。尤其第二段,“科目”是如何和“分类”挂上钩的?请高手简单解释一下。谢谢!
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode
Dim dt As DataTable = DataTables("会计科目")
tr.StopRedraw()
tr.Nodes.Clear
tr.Nodes.Add("全部")
For Each dr As DataRow In dt.datarows
If dr.IsNull("科目代码") = False AndAlso dr("科目代码").Length = 4 Then
nd = tr.Nodes.Add(dr("科目代码"),dr("科目代码") & " " & dr("科目名称"))
Functions.Execute("AddChildren",nd,dt)
End If
Next
tr.ResumeRedraw()
---------------------------------
Dim tr As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim rts() As String = {"全部","资产","负债","权益","成本","损益"}
Dim nd As WinForm.TreeNode
Dim dt As DataTable = DataTables("会计科目")
tr.StopRedraw()
tr.Nodes.Clear
For Each rt As String In rts
tr.Nodes.Add(rt)
Next
For Each dr As DataRow In dt.datarows
If dr.IsNull("科目代码") = False AndAlso dr("科目代码").Length = 4 Then
Dim i As Integer = CInt(dr("科目代码").Substring(0,1))
nd = tr.Nodes(i).Nodes.Add(dr("科目代码"),dr("科目代码") & " " & dr("科目名称"))
Functions.Execute("AddChildren",nd,dt)
End If
Next
tr.ResumeRedraw()