以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  for each 未将对象引用设置到对象的实例,已解决!  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=92813)

--  作者:rightinfo2014
--  发布时间:2016/11/14 10:54:00
--  for each 未将对象引用设置到对象的实例,已解决!


图片点击可在新窗口打开查看此主题相关图片如下:for each未将对象引用设置到对象的实例.png
图片点击可在新窗口打开查看
这段代码

For Each nd As WinForm.TreeNode In trv.AllNodes
    output.Show(99)
    If nd.Name > "全部编码" Then
        output.Show(21)
        If nd.DataRow("上级组") = True Then
            txt = nd.DataRow("编码") & " " & nd.DataRow("编码名称")
            nd.text = txt
            output.Show(22)   

        end if 

    end if

next

运行结果报错如上图,请教谁能帮我指正一下吗?我错在哪里了。谢谢!

 

 备注,以上截图中,命令窗口提示,程序运行到output.show(99)后就出错了。
 
[此贴子已经被作者于2016/11/14 13:08:09编辑过]

--  作者:blackzhu
--  发布时间:2016/11/14 11:04:00
--  
  For Each nd As WinForm.TreeNode In trv.AllNodes
                    Select Case nd.Level
                        Case 0 \'看下是第几层节点,这边是第一层
                            If nd.Name <> "全部编码" Then \'不等于,拿来的大于和小于呢,又不是数值
                                If nd.DataRow("上级组") = True Then
                                    txt = nd.DataRow("编码") & " " & nd.DataRow("编码名称")
                                    nd.Text = txt
                                    Output.Show(22)

                                End If

                            End If
                    End Select
                Next
--  作者:有点色
--  发布时间:2016/11/14 12:08:00
--  

 如果有新增的节点,它们是不会有datarow属性值的。

 

For Each nd As WinForm.TreeNode In trv.AllNodes
    If nd.Name > "全部编码" Then
        If nd.DataRow isnot nothing andalso nd.DataRow("上级组") = True Then
            txt = nd.DataRow("编码") & " " & nd.DataRow("编码名称")
            nd.text = txt          
        End If      
    End If
Next


--  作者:rightinfo2014
--  发布时间:2016/11/14 13:07:00
--  
多谢
blackzhu,按照您的指导问题解决了。