以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [讨论]TreeView1索引超出了数组界限 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=110168) |
-- 作者:乡里出城 -- 发布时间:2017/11/28 10:29:00 -- [讨论]TreeView1索引超出了数组界限 递归会计科目后,想直接引用如图圈的科目,结果出现TreeView1索引超出了数组界限, 首先
我在TreeView1窗口NodeMouseDoubleClick事件的代码是 Dim str As String = "" For Each s As String In e.Node.FullPath.split("\\") str &= s.Split(" ")(1) & "\\" Next CurrentTable.Value = str.trim("\\") 如果把该窗口中AfterLoad的 代码一: 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.Select("", "科目代码") 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() 改成 代码二: 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.Select("","科目代码") 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() 这样就能正常引用,但我还是想用代码一的方式来体现递归科目,应如何改TreeView1窗口NodeMouseDoubleClick事件的代码?内部函数我跟帮助案例里的一样 |
-- 作者:有点甜 -- 发布时间:2017/11/28 10:34:00 -- 改成
Dim str As String = ""
Dim ary() = e.Node.FullPath.split("\\")
For i As integer = 1 to ary.length-1
Dim s As String = ary(i)
str &= s.Split(" ")(1) & "\\"
Next
CurrentTable.Value = str.trim("\\")
|