|
-
Jan 29th, 2010, 10:38 PM
#1
Thread Starter
Junior Member
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
-
Jan 30th, 2010, 04:25 AM
#2
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|