Foxtable(狐表)用户栏目专家坐堂 → [讨论]TreeView1索引超出了数组界限


  共有1936人关注过本帖树形打印复制链接

主题:[讨论]TreeView1索引超出了数组界限

帅哥哟,离线,有人找我吗?
乡里出城
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:426 积分:3505 威望:0 精华:0 注册:2015/4/17 9:13:00
[讨论]TreeView1索引超出了数组界限  发帖心情 Post By:2017/11/28 10:29:00 [只看该作者]

递归会计科目后,想直接引用如图圈的科目,结果出现TreeView1索引超出了数组界限,


图片点击可在新窗口打开查看此主题相关图片如下:索引超出了数组界限.png
图片点击可在新窗口打开查看


首先

我在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事件的代码?内部函数我跟帮助案例里的一样

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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("\")

 回到顶部