Home All Groups Group Topic Archive Search About

i need to implement drag and drop in treeview in VB

Author
7 Aug 2006 11:24 AM
pooja
i need to implement drag and drop in treeview in VB.
Kindly help.
My treeview contains activities maintained using XML Files.
Hopefully, Thanks.

Author
7 Aug 2006 4:09 PM
redeagle
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

Show quoteHide quote
"pooja" wrote:

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