以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  TreeView累计子节点数据  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=100614)

--  作者:papa8399
--  发布时间:2017/5/15 11:15:00
--  TreeView累计子节点数据

 目的:通过递归算法实现子节点对应表中行的数值列的累计计算,但出现了系统错误,说明如下:


1. 数据源

图片点击可在新窗口打开查看


2. 命令窗口的程序代码


Forms("Win1").open()
Dim tr As WinForm.TreeView = Forms("Win1").Controls("TreeView1")
Dim tb As Table = Tables("TbTree")
tr.GenerateTree(DataTables("TbTree"),"Cod","ValueA",".")  \'显示ValueA,用与于程序结果核对
Forms("Win1").show()

For Each nd As WinForm.TreeNode In tr.nodes
    If nd.nodes.Count = 0 Then
        nd.ParentNode.DataRow("ValueA")+=nd.DataRow("ValueA")
        nd.ParentNode.DataRow("ValueB")+=nd.DataRow("ValueB")
    Else
        Functions.Execute("CalChild",tb,tr,nd)
        nd.ParentNode.DataRow("ValueA")+=nd.DataRow("ValueA")
        nd.ParentNode.DataRow("ValueB")+=nd.DataRow("ValueB")
    End If
Next


3. 内部函数代码

Dim tb As Table = args(0)
Dim tr As WinForm.TreeView = args(1)
Dim nd As WinForm.TreeNode = args(2)

For Each ndcd As WinForm.TreeNode In nd.nodes
    If ndcd.nodes.count=0 Then
        ndcd.ParentNode.DataRow("ValueA")+=ndcd.DataRow("ValueA")
        ndcd.ParentNode.DataRow("ValueB")+=ndcd.DataRow("ValueB")
    Else
        Functions.Execute("CalChild",tb,tr,ndcd)
        ndcd.ParentNode.DataRow("ValueA")+=ndcd.DataRow("ValueA")
        ndcd.ParentNode.DataRow("ValueB")+=ndcd.DataRow("ValueB")
    End If
Next


4. 显示结果及未知的系统错误


系统错误

图片点击可在新窗口打开查看


但仍然能显示结果:

图片点击可在新窗口打开查看


图片点击可在新窗口打开查看


??请大师指点,改正错误??




--  作者:有点蓝
--  发布时间:2017/5/15 11:38:00
--  
判断一下

......
For Each ndcd As WinForm.TreeNode In nd.nodes
   if ndcd.ParentNode isnot nothing then
    If ndcd.nodes.count=0 Then
        ndcd.ParentNode.DataRow("ValueA")+=ndcd.DataRow("ValueA")
        ndcd.ParentNode.DataRow("ValueB")+=ndcd.DataRow("ValueB")
    Else
        Functions.Execute("CalChild",tb,tr,ndcd)
        ndcd.ParentNode.DataRow("ValueA")+=ndcd.DataRow("ValueA")
        ndcd.ParentNode.DataRow("ValueB")+=ndcd.DataRow("ValueB")
    End If
   end if
Next