Help - TreeView Question

K

Kelvin Leung

Hi

I use Drag and Drop between 2 TreeView Control under VB.Net
But I found that it cannot work when I add sub-class for each node

Is it drag and drop method cannot work when the node with sub-class ?

If no, any related information/reference ?

Thanks a lot
Kelvin
 
C

Chris Calzaretta

post code that your having problems with.
You should be able to drag and drop from nodes with in nodes. As Explorer
which is the tree view.
 
K

Kelvin Leung

Hi Chris

Thanks for your reply !

I would like to know why cannot work (Drag and Drop) after put sub-class
under treenode

And my source code as following :

Data Initial :
Can Work :
/*===============

With tvwLeft.Nodes
.Clear()
.Add(¡§Left Node 1¡¨)

.Add(¡§Left Node 2¡¨)
End With



With tvwRight.Nodes

.Clear()
.Add(¡§Right Node 1¡¨)

.Add(¡§Right Node 2¡¨)
End With

/*===============



Cannot Work After Added Sub-Class Information :
/*===============

Class myTreeNode

Inherits TreeNode

Public MyShowText As String

Public MyIntg As Integer

Public MyStrng As String

Sub New(ByVal ShowText As String, ByVal Intg As Integer, ByVal
Strng As String)

MyBase.New()

MyShowText = ShowText

MyIntg = Intg

MyStrng = Strng

Me.Text = MyShowText

End Sub

End Class



With tvwLeft.Nodes

.Clear()

.Add(New myTreeNode("Left Node 1", 1, "Left Node Information"))

.Add(New myTreeNode("Left Node 2", 2, "Left Node Information"))

End With



With tvwRight.Nodes

.Clear()

.Add(New myTreeNode("Right Node 1", 1, "Right Node
Information"))

.Add(New myTreeNode("Right Node 2", 2, "Right Node
Information"))

End With

/*===============


Drag and Drop Handling :
/*===============

Private Sub TreeView_DragDrop(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DragEventArgs) _
Handles tvwLeft.DragDrop, tvwright.DragDrop


Dim OriginationNode As TreeNode =
CType(e.Data.GetData("System.Windows.Forms.TreeNode"), 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)



DestinationNode.Nodes.Add(CType(OriginationNode.Clone,
TreeNode))

DestinationNode.Expand()

End Sub



Private Sub TreeView_DragEnter(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DragEventArgs) _

Handles tvwLeft.DragEnter, tvwright.DragEnter



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

e.Effect = DragDropEffects.Copy

Else

e.Effect = DragDropEffects.None

End If

End Sub



Private Sub TreeView_ItemDrag(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.ItemDragEventArgs) _

Handles tvwLeft.ItemDrag, tvwright.ItemDrag



If e.Button = MouseButtons.Left Then

DoDragDrop(e.Item, DragDropEffects.Copy)

End If

End Sub

/*===============


Thanks
Kelvin Leung
 
C

Chris Calzaretta

As it looks it I think it seems to lay around

Dim DestinationNode As TreeNode

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

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

and your not grabing the correct node

If you want I can help more. If you want you can shot a copy of the code to
(e-mail address removed)
 

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