Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 

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

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Posted

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

George C.K. Low

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...