468,133 Members | 1,574 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

i need to implement drag and drop in treeview in VB

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

Aug 7 '06 #1
1 1614
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).T oString)

End Sub

"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.

Aug 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Peter Flickinger | last post: by
1 post views Thread by Kevin Henkener | last post: by
4 posts views Thread by Qingdong Z. | last post: by
1 post views Thread by emferrari | last post: by
2 posts views Thread by Yoshitha | last post: by
reply views Thread by munishbatra2002 | last post: by
2 posts views Thread by bob | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.