TheWizardofInt
Junior Contributor
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?
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