Drag files from Windows Explorer to Treeview

TheWizardofInt

Junior Contributor
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
I am trying to drag files from subdirectories in Windows Explorer to Treeview

No matter how I code the thing, it says that the drag as no data, and therefore doesn't populate

What am I doing wrong here?

Code:
Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
        Dim oNode As New System.Windows.Forms.TreeNode

        If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", False) Then
            Try
                For Each oNode In TreeView1.Nodes
                    oNode.Remove()
                Next
                oNode.ImageIndex = 0    ' Closed folder 
                oNode.SelectedImageIndex = 0
                oNode.Text = e.Data.GetData(DataFormats.Text).ToString()
                'oNode.Text = e.Data.GetData("System.Windows.Forms.TreeNode")
                TreeView1.Nodes.Add(oNode)
                oNode.Nodes.Add("")
                'TreeView1.Nodes.Add(oNode)
            Catch ex As Exception
                MsgBox("Cannot create initial node:" & ex.ToString)
                End
            End Try
        End If
    End Sub

    Private Sub TreeView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragEnter
        e.Effect = DragDropEffects.Copy
        ' If the data is text, copy the data tao the RichTextBox control.
        If e.Data.GetDataPresent(DataFormats.Text) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub TreeView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag
        DoDragDrop(e.Item, DragDropEffects.Copy)
    End Sub
 
this happened to me before as well.
Actually there is a workaround availlable in MSDN. But I forgot where already..

Anyway, I had found out a c-sharp version of the workaround from Google. Feel free to have a look on here
 
Back
Top