以文本方式查看主题

-  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=12220)

--  作者:紙上不談兵
--  发布时间:2011/8/26 11:49:00
--  [求助]帮忙分析代码哪出错了?
把此文件替换范例的[目录树管理],代码详见AfterSelectNode,
想法:设置节点BackColor,标记最近选择4个节点.

随便选择节点,点击多次就会间中报错!实在不知哪错了?请大家帮忙分析一下,多谢!

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:目录树管理.table



图片点击可在新窗口打开查看此主题相关图片如下:000.gif
图片点击可在新窗口打开查看

--  作者:狐狸爸爸
--  发布时间:2011/8/26 12:09:00
--  

If Lsj.Contains(e.Node.Text) = False Then
   Lsj.Add(e.Node.Text)
End If
e.Form.Controls("TextBox2").value =Nothing
For Each s As String In Lsj  
    e.Form.Controls("TextBox2").value += "," & s
Next

If Lsj.count>3 Then
    For Each nd As WinForm.TreeNode In e.Sender.AllNodes
        If nd.Text = Lsj(0) Then
            nd.BackColor = Color.White
            Lsj.RemoveAt(0)
            If lsJ.Count =0 Then
                Exit For
            End If
        End If
    Next  
End If

For Each nd As WinForm.TreeNode In e.Sender.AllNodes
    For Each s As String In Lsj
        If nd.Text = s Then
            nd.BackColor = Color.LightGray
        End If
    Next
Next


--  作者:紙上不談兵
--  发布时间:2011/8/26 12:34:00
--  
以下是引用狐狸爸爸在2011-8-26 12:09:00的发言:

If Lsj.Contains(e.Node.Text) = False Then
   Lsj.Add(e.Node.Text)
End If
e.Form.Controls("TextBox2").value =Nothing
For Each s As String In Lsj  
    e.Form.Controls("TextBox2").value += "," & s
Next

If Lsj.count>3 Then
    For Each nd As WinForm.TreeNode In e.Sender.AllNodes
        If nd.Text = Lsj(0) Then
            nd.BackColor = Color.White
            Lsj.RemoveAt(0)
            If lsJ.Count =0 Then
                Exit For
            End If
        End If
    Next  
End If

For Each nd As WinForm.TreeNode In e.Sender.AllNodes
    For Each s As String In Lsj
        If nd.Text = s Then
            nd.BackColor = Color.LightGray
        End If
    Next
Next


多谢先!

这个是不报错了,只是有点不明:我设置了If Lsj.count>3 Then才执行If...End if里面的代码呀,为何里面还须 

If lsJ.Count =0 Then

       Exit For
End If            呢?
且虽不报错,但有时结果不对:见图,TextBox2显示Lsj有[数码产品,电脑,电脑配件,机箱,主板]5个值,但标记只有[主板]

图片点击可在新窗口打开查看此主题相关图片如下:00.gif
图片点击可在新窗口打开查看


--  作者:紙上不談兵
--  发布时间:2011/8/26 13:11:00
--  

明白哪出错了:如不加Exit For,则Lsj为空时执行RemoveAt(0)会报错!多谢狐爸,正确的是:


If Lsj.Contains(e.Node.Text) = False Then
   Lsj.Add(e.Node.Text)
End If

If Lsj.count>3 Then
    For Each nd As WinForm.TreeNode In e.Sender.AllNodes
        If nd.Text = Lsj(0) Then
            nd.BackColor = Color.White
            Lsj.RemoveAt(0)      
               Exit For        
        End If
    Next   
End If


For Each nd As WinForm.TreeNode In e.Sender.AllNodes
    For Each s As String In Lsj
        If nd.Text = s Then
            nd.BackColor = Color.LightGray
        End If
    Next
Next


--  作者:狐狸爸爸
--  发布时间:2011/8/26 14:03:00
--  

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