By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

Help - TreeView Question

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.


"Kelvin Leung" <ke*******@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #2

P: n/a
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.TreeNod e"), TreeNode)

If e.Data.GetDataPresent("System.Windows.Forms.TreeNo de", 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.Cl one,
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.TreeN ode")) 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


"Chris Calzaretta" <cc*********@hotmail.com> ¦b¶l¥ó
news:%2****************@TK2MSFTNGP14.phx.gbl ¤¤¼¶¼g...
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.


"Kelvin Leung" <ke*******@hotmail.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
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


Nov 21 '05 #3

P: n/a


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
Ch*************@mn.rr.com

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.