TreeView Drag & Drop 
Author Message
 TreeView Drag & Drop

I found this code snippet in the knowledge base.  It was for dragging from 1
Tree to another.  I removed the references to tree2 so that I could d & d
within the 1 tree (TreeView1).  Cant get it to work and am wondering what
I'm doing wrong.......
Also as the mouse gets drug across the tree how can I make it select the
approiate node

TIA for any help.....see following code....am I even close?
meh

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

Dim ParentNode1 As TreeNode

Dim ParentNode2 As TreeNode

ParentNode1 = TreeView1.Nodes.Add("Root Node")

With ParentNode1

.Nodes.Add("r1FirstChild")

.Nodes.Add("r1SecondChild")

.Nodes.Add("r1ThirdChild")

.Nodes.Add("r1FourthChild")

.Expand()

End With

ParentNode2 = TreeView1.Nodes.Add("Root Node2")

With ParentNode2

.Nodes.Add("r2FirstChild")

.Nodes.Add("r2SecondChild")

.Nodes.Add("r2ThirdChild")

.Nodes.Add("r2FourthChild")

.Expand()

End With

End Sub

'***************************************************************************
*************************

'This code initiates a move operation on the item that is being dragged.

Public Sub TreeView1_ItemDrag(ByVal sender As Object, ByVal e As
ItemDragEventArgs) Handles TreeView1.ItemDrag, TreeView1.ItemDrag

DoDragDrop(e.Item, DragDropEffects.Move)

End Sub

'***************************************************************************
*********************

' method handler to handle the DragEnter event of TreeView1

Public Sub TreeView1_DragEnter(ByVal sender As Object, ByVal e As
DragEventArgs) Handles TreeView1.DragEnter, TreeView1.DragEnter

e.Effect = DragDropEffects.Move

End Sub

'***************************************************************************
*********************

Public Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As
DragEventArgs) Handles TreeView1.DragDrop, TreeView1.DragEnter

Dim NewNode As TreeNode

If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", False) Then

Dim pt As Point

Dim DestinationNode As TreeNode

pt = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y))

DestinationNode = CType(sender, TreeView).GetNodeAt(pt)

NewNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode)

If Not DestinationNode.TreeView Is NewNode.TreeView Then

DestinationNode.Nodes.Add(NewNode.Clone)

DestinationNode.Expand()

'Remove original node

NewNode.Remove()

End If

End If

End Sub



Tue, 07 Jun 2005 21:55:12 GMT  
 TreeView Drag & Drop
I got it thanks...

meh

Quote:
> I found this code snippet in the knowledge base.  It was for dragging from
1
> Tree to another.  I removed the references to tree2 so that I could d & d
> within the 1 tree (TreeView1).  Cant get it to work and am wondering what
> I'm doing wrong.......
> Also as the mouse gets drug across the tree how can I make it select the
> approiate node

> TIA for any help.....see following code....am I even close?
> meh

> Private Sub Form1_Load(ByVal sender As System.Object, _

> ByVal e As System.EventArgs) Handles MyBase.Load

> Dim ParentNode1 As TreeNode

> Dim ParentNode2 As TreeNode

> ParentNode1 = TreeView1.Nodes.Add("Root Node")

> With ParentNode1

> .Nodes.Add("r1FirstChild")

> .Nodes.Add("r1SecondChild")

> .Nodes.Add("r1ThirdChild")

> .Nodes.Add("r1FourthChild")

> .Expand()

> End With

> ParentNode2 = TreeView1.Nodes.Add("Root Node2")

> With ParentNode2

> .Nodes.Add("r2FirstChild")

> .Nodes.Add("r2SecondChild")

> .Nodes.Add("r2ThirdChild")

> .Nodes.Add("r2FourthChild")

> .Expand()

> End With

> End Sub

'***************************************************************************
Quote:
> *************************

> 'This code initiates a move operation on the item that is being dragged.

> Public Sub TreeView1_ItemDrag(ByVal sender As Object, ByVal e As
> ItemDragEventArgs) Handles TreeView1.ItemDrag, TreeView1.ItemDrag

> DoDragDrop(e.Item, DragDropEffects.Move)

> End Sub

'***************************************************************************
Quote:
> *********************

> ' method handler to handle the DragEnter event of TreeView1

> Public Sub TreeView1_DragEnter(ByVal sender As Object, ByVal e As
> DragEventArgs) Handles TreeView1.DragEnter, TreeView1.DragEnter

> e.Effect = DragDropEffects.Move

> End Sub

'***************************************************************************

- Show quoted text -

Quote:
> *********************

> Public Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As
> DragEventArgs) Handles TreeView1.DragDrop, TreeView1.DragEnter

> Dim NewNode As TreeNode

> If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", False) Then

> Dim pt As Point

> Dim DestinationNode As TreeNode

> pt = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y))

> DestinationNode = CType(sender, TreeView).GetNodeAt(pt)

> NewNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode)

> If Not DestinationNode.TreeView Is NewNode.TreeView Then

> DestinationNode.Nodes.Add(NewNode.Clone)

> DestinationNode.Expand()

> 'Remove original node

> NewNode.Remove()

> End If

> End If

> End Sub



Thu, 09 Jun 2005 21:44:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Treeview - Drag & Drop

2. TreeView, drag & drop, and OLEStartDrag

3. Treeview Drag & Drop

4. TreeView, Drag & Drop

5. Drag & Drop with TreeView control

6. ole drag&drop of file from an activex/ treeview headache

7. TreeView + ListView +Drag&Drop

8. Drag&Drop from NT Explorer to the treeview control

9. Drag&Drop in treeview

10. TreeView with Drag & Drop

11. Drag&Drop in Treeview with HitTest and DropHighlight

12. Drag & Drop in TreeView

 

 
Powered by phpBB® Forum Software