Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Dir Structure from TreeView

Dir Structure from TreeView

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brad Fackrell
    wrote on last edited by
    #1

    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

    B 2 Replies Last reply
    0
    • B Brad Fackrell

      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

      B Offline
      B Offline
      Brad Fackrell
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • B Brad Fackrell

        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

        B Offline
        B Offline
        Brad Fackrell
        wrote on last edited by
        #3

        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
        
        M 1 Reply Last reply
        0
        • B Brad Fackrell

          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
          
          M Offline
          M Offline
          Marc 0
          wrote on last edited by
          #4

          Why dont you store the original full path to TreeNode.Tag (when you are creating the node)?


          B 1 Reply Last reply
          0
          • M Marc 0

            Why dont you store the original full path to TreeNode.Tag (when you are creating the node)?


            B Offline
            B Offline
            Brad Fackrell
            wrote on last edited by
            #5

            Good idea. Thanks.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups