树节点从折叠展开时重复

发布于 2024-09-07 20:44:35 字数 1976 浏览 7 评论 0原文

子节点中的项目似乎每次从折叠状态展开时都会自我复制。我认为问题是在扩展之前需要清除内存。任何人都可以明白为什么会发生此事件。提前致谢。

  Public Sub FillTree(ByVal s As String)
        Dim nodeText As String = ""
        Dim sb As New C_StringBuilder
        With My.Computer.FileSystem
            For i As Integer = 0 To .Drives.Count - 1
                '** Build the drive's node text
                sb.ClearText()
                sb.AppendText(.Drives(i).Name.ToString)
                nodeText = sb.FullText
                'Check to see if DropDown Selection is the same as what has been read into i
                If (sb.FullText = s) Then
                    '** Add the drive to the treeview
                    Dim driveNode As TreeNode
                    tvFolders.Nodes.Clear()
                    driveNode = tvFolders.Nodes.Add(nodeText)
                    driveNode.Tag = .Drives(i).Name
                    '** Add the next level of subfolders
                    ListLocalSubFolders(driveNode, .Drives(i).Name)
                End If
            Next
        End With
    End Sub

Private Sub ListLocalSubFolders(ByVal ParentNode As TreeNode, ByVal sParentPath As String)
    '    ' Add all local subfolders below the passed Local treeview node
    Dim s As String
    Try
        For Each s In Directory.GetDirectories(sParentPath)
            Dim childNode As TreeNode
            childNode = ParentNode.Nodes.Add(FilenameFromPath(s))
            childNode = Nothing
        Next
    Catch ex As Exception
    End Try
End Sub

Private Sub tvFolders_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvFolders.BeforeExpand

    ' Populate all child nodes below the selected node
    Dim parentPath As String = e.Node.Tag
    Dim childNode As TreeNode = e.Node.FirstNode
    Do While childNode IsNot Nothing
        ListLocalSubFolders(childNode, parentPath & childNode.Text)
        childNode = childNode.NextNode
    Loop


End Sub

Items in the child node seem to replicate themselves everytime when expanded from a collapsed state. I think the problem is that the memory needs to be cleared before I expand. Can anyone see why this event would occur. Thanks in Advance.

  Public Sub FillTree(ByVal s As String)
        Dim nodeText As String = ""
        Dim sb As New C_StringBuilder
        With My.Computer.FileSystem
            For i As Integer = 0 To .Drives.Count - 1
                '** Build the drive's node text
                sb.ClearText()
                sb.AppendText(.Drives(i).Name.ToString)
                nodeText = sb.FullText
                'Check to see if DropDown Selection is the same as what has been read into i
                If (sb.FullText = s) Then
                    '** Add the drive to the treeview
                    Dim driveNode As TreeNode
                    tvFolders.Nodes.Clear()
                    driveNode = tvFolders.Nodes.Add(nodeText)
                    driveNode.Tag = .Drives(i).Name
                    '** Add the next level of subfolders
                    ListLocalSubFolders(driveNode, .Drives(i).Name)
                End If
            Next
        End With
    End Sub

Private Sub ListLocalSubFolders(ByVal ParentNode As TreeNode, ByVal sParentPath As String)
    '    ' Add all local subfolders below the passed Local treeview node
    Dim s As String
    Try
        For Each s In Directory.GetDirectories(sParentPath)
            Dim childNode As TreeNode
            childNode = ParentNode.Nodes.Add(FilenameFromPath(s))
            childNode = Nothing
        Next
    Catch ex As Exception
    End Try
End Sub

Private Sub tvFolders_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvFolders.BeforeExpand

    ' Populate all child nodes below the selected node
    Dim parentPath As String = e.Node.Tag
    Dim childNode As TreeNode = e.Node.FirstNode
    Do While childNode IsNot Nothing
        ListLocalSubFolders(childNode, parentPath & childNode.Text)
        childNode = childNode.NextNode
    Loop


End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆流 2024-09-14 20:44:35

这行必须:

ListLocalSubFolders(childNode, parentPath & childNode.Text)

不是这样的:

ListLocalSubFolders(childNode, childNode.Text)

否则你会得到这样的东西:“C:\C:\$Recycle.Bin”

Must this line:

ListLocalSubFolders(childNode, parentPath & childNode.Text)

not look like this:

ListLocalSubFolders(childNode, childNode.Text)

?

Otherwise you will get f.e. something like this: "C:\C:\$Recycle.Bin"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文