以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  遍历目录树的节点出错?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=83487)

--  作者:happyft
--  发布时间:2016/4/10 22:39:00
--  遍历目录树的节点出错?
在目录树的afterchecked事件中写了如下代码:

If nd1.checked = False Then
    If nd1.level = 0 Then
        For Each nd As WinForm.TreeNode In tr2.Nodes
            If nd1.name = nd.name Then \'如果是取消勾选父节点直接将目标目录树中对应的节点清除
                nd.Delete \'删除节点
                Exit For
            End If
        Next
    ElseIf nd1.level = 1 Then
        For Each nd As WinForm.TreeNode In tr2.AllNodes
            msgbox(1)
            If nd1.ParentNode.name = nd.ParentNode.name AndAlso nd1.name = nd.name Then \'父子节点均相同才将目标目录树中对应的节点清除
                nd.delete  \'删除节点
                Exit For
            End If
        Next
    End If

一行到到上面红色的代码时就出错(提示未将对象的引用设置到对象的实例),怎么都找不出原因?是哪里写错了
谢谢!

--  作者:大红袍
--  发布时间:2016/4/11 0:05:00
--  
For Each nd As WinForm.TreeNode In tr2.AllNodes
    If nd.Level = 1 Then
        If nd1.ParentNode.name = nd.ParentNode.name AndAlso nd1.name = nd.name Then \'父子节点均相同才将目标目录树中对应的节点清除
            nd.delete  \'删除节点
            Exit For
        End If
    End If
Next