Dir Structure from TreeView
-
Does anybody know how I could use a TreeView structure to create a file structure? In other words, I want to write my TreeView out to a specified location on my C:\ drive and build folders that mimic my TreeView. …and to make matters even more complicated, each of my folders contains files that need to be moved. Here is what I have: I read and existing file structure from my computer drive into a TreeView. I then rearrange the file structure in the TreeView. Now, I need to files to be moved (with their contents) to the new locations. Thanks Brad
-
Does anybody know how I could use a TreeView structure to create a file structure? In other words, I want to write my TreeView out to a specified location on my C:\ drive and build folders that mimic my TreeView. …and to make matters even more complicated, each of my folders contains files that need to be moved. Here is what I have: I read and existing file structure from my computer drive into a TreeView. I then rearrange the file structure in the TreeView. Now, I need to files to be moved (with their contents) to the new locations. Thanks Brad
I was thinking of something along the lines of: When a node is selected, write its full path to originalPosition. When a destination is selected, write its full path to newPosition and:
IO.File.Copy(originalPosition, newPosition)
Is there a way to copy/move a file and its contents (including subfolders)? Thanks Brad -
Does anybody know how I could use a TreeView structure to create a file structure? In other words, I want to write my TreeView out to a specified location on my C:\ drive and build folders that mimic my TreeView. …and to make matters even more complicated, each of my folders contains files that need to be moved. Here is what I have: I read and existing file structure from my computer drive into a TreeView. I then rearrange the file structure in the TreeView. Now, I need to files to be moved (with their contents) to the new locations. Thanks Brad
I've made a little more progress but now I'm stuck on a drag/drop problem. Does anybody know how to store the fullpath of a selected node during a drag and drop procedure? Here is what I have tried (in every variation that I can think of):
Dim originalPosition As String
Private sub [tried several methods]
originalPosition = TreeView1.SelectedNode.FullPath [...tried multiple properties]
End sub
At the start of the drag/drop the original path is stored in
originalPosition
but after the drag/drop is complete,originalPosition
has changed to the new full path. I don’t understand how this is happening. Does anybody understand the drag/drop procedures enough to see what is going on? Here is the code that I'm using for the drag/drop:Public Sub TreeView1\_ItemDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag DoDragDrop(e.Item, DragDropEffects.Move) End Sub Public Sub TreeView1\_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragEnter If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Private Sub TreeView1\_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) = False Then Exit Sub Dim selectedTreeview As TreeView = CType(sender, TreeView) Dim pt As Point = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y)) Dim targetNode As TreeNode = selectedTreeview.GetNodeAt(pt) If Not (selectedTreeview Is targetNode) Then selectedTreeview.SelectedNode = targetNode Dim dropNode As TreeNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode) Do Until targetNode Is Nothing If targetNode Is dropNode Then e.Effect = DragDropEffects.None Exit Sub End If targetNode = targetNode.Parent Loop End If e.Effect = DragDropEffects.Move End Sub Private Sub TreeView1\_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop If e.Data.GetDataPresent("System.W
-
I've made a little more progress but now I'm stuck on a drag/drop problem. Does anybody know how to store the fullpath of a selected node during a drag and drop procedure? Here is what I have tried (in every variation that I can think of):
Dim originalPosition As String
Private sub [tried several methods]
originalPosition = TreeView1.SelectedNode.FullPath [...tried multiple properties]
End sub
At the start of the drag/drop the original path is stored in
originalPosition
but after the drag/drop is complete,originalPosition
has changed to the new full path. I don’t understand how this is happening. Does anybody understand the drag/drop procedures enough to see what is going on? Here is the code that I'm using for the drag/drop:Public Sub TreeView1\_ItemDrag(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag DoDragDrop(e.Item, DragDropEffects.Move) End Sub Public Sub TreeView1\_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragEnter If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub Private Sub TreeView1\_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) = False Then Exit Sub Dim selectedTreeview As TreeView = CType(sender, TreeView) Dim pt As Point = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y)) Dim targetNode As TreeNode = selectedTreeview.GetNodeAt(pt) If Not (selectedTreeview Is targetNode) Then selectedTreeview.SelectedNode = targetNode Dim dropNode As TreeNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode) Do Until targetNode Is Nothing If targetNode Is dropNode Then e.Effect = DragDropEffects.None Exit Sub End If targetNode = targetNode.Parent Loop End If e.Effect = DragDropEffects.Move End Sub Private Sub TreeView1\_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop If e.Data.GetDataPresent("System.W
-
Why dont you store the original full path to TreeNode.Tag (when you are creating the node)?
Good idea. Thanks.