i need to implement drag and drop in treeview in VB

P

pooja

i need to implement drag and drop in treeview in VB.
Kindly help.
My treeview contains activities maintained using XML Files.
Hopefully, Thanks.
 
G

Guest

Hi Pooja-

You can implement drag and drop with the DataObject (the "clipboard").

In the form that hosts the TreeView control (perhaps in the TreeViews
MouseMove Event):

Private Sub treeFileInfoTree_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles treeFileInfoTree.MouseMove

Dim tBase as TreeView
Dim data as New DataObject
'If no mouse button pressed, then assume no dragdrop
If e.Button = MouseButtons.None Then Exit Sub
tBase = DirectCast(sender, TreeView)
'Exit sub if button pressed but mouse is not over treeview node
If tBase.SelectedNode.Bounds.Contains(e.X, e.Y) Then Exit Sub
'Assign data to clipboard
data.SetData(DataFormats.Text, tBase.SelectedNode.Text)
'Begin Drag Operation
Dim effect As DragDropEffects = DragDropEffects.Copy
effect = tBase.DoDragDrop(data, effect) 'wait here until drop complete

End Sub

Then you need to add code to the DragDrop event of the control where the
drop is occuring:

Private Sub ListBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles lstOriginal.DragDrop

Dim lBase As ListBox = DirectCast(sender, ListBox)
lBase.Items.Add(e.Data.GetData(DataFormats.Text).ToString)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top