Results 1 to 2 of 2

Thread: TreeNode refreshing, deleting files...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2010
    Posts
    16

    Smile TreeNode refreshing, deleting files...

    here is the code i use for adding folders to the treenode. it works great but i want a delete button for deleting both files and folders... and how can i make the treenode auto refreshing. or refreshing when exiting another form...

    Code:
        Private Sub PopulateTreeView(ByVal dir As String, ByVal parentNode As TreeNode)
    
            Dim folder As String = String.Empty
    
            Try
    
                'Add the files to treeview
    
                Dim files() As String = IO.Directory.GetFiles(dir)
    
                If files.Length <> 0 Then
    
                    Dim fileNode As TreeNode = Nothing
    
                    For Each file As String In files
    
                        fileNode = parentNode.Nodes.Add(IO.Path.GetFileName(file))
    
                        fileNode.Tag = file
    
                    Next
    
                End If
    
    
    
                'Add folders to treeview
    
                Dim folders() As String = IO.Directory.GetDirectories(dir)
    
                If folders.Length <> 0 Then
    
                    Dim folderNode As TreeNode = Nothing
    
                    Dim folderName As String = String.Empty
    
                    For Each folder In folders
    
                        folderName = IO.Path.GetFileName(folder)
    
                        folderNode = parentNode.Nodes.Add(folderName)
    
                        folderNode.Tag = folder
    
                        PopulateTreeView(folder, folderNode)
    
                    Next
    
                End If
    
            Catch ex As UnauthorizedAccessException
    
                parentNode.Nodes.Add("Access Denied")
    
            End Try
    
        End Sub
    
    
    
        Private Sub treeload(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'New TreeNode tn
            Dim tn As New TreeNode("Projects")
            PopulateTreeView("C:\____________________", tn)
            TreeView1.Nodes.Add(tn)
            'New TreeNode Sc
            Dim sc As New TreeNode("Sample Code")
            PopulateTreeView("C:\____________________", sc)
            TreeView1.Nodes.Add(sc)
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: TreeNode refreshing, deleting files...

    It's not auto-refreshing. You have to refresh it. Whatever code you used to populate the node in the first place, you need to execute the same code again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width