Subclass problem, please help
Hi Everyone,
Ive got this problem when creating a sub class to a treenode.
Code:
Class DomainNode
Inherits TreeNode
Public DomainRow As DataRow
' Public DomainID As Integer
' Public ParentDomainID As Integer
Public Sub New(ByVal DRow As DataRow)
MyBase.new()
Me.Text = DRow.Item("Name")
DomainRow = DRow
End Sub
End Class
After the tree is built using the following syntax
TreeView1.Nodes.Add(CType(New DomainNode(NRow), TreeNode))
I'm trying to implement drag and drop operation on it as follows. The problem is in TreeView1_DragEnter sub. For some reason it fails to locate treenode data and I don't know why or what should I do I'm new to it. Please help
Code:
Private Sub TreeView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag
If e.Button.Left Then
TreeView1.DoDragDrop(TreeView1.SelectedNode, DragDropEffects.Copy)
End If
End Sub
Private Sub TreeView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragEnter
If (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TreeView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragDrop
Dim pt As Point
Dim DestinationNode As TreeNode
Dim OriginalRow, DestinationRow As DataRow
Dim OriginalNode As TreeNode = CType(e.Data.GetData("System.Windows.Forms.TreeNode"), TreeNode)
pt = CType(sender, TreeView).PointToClient(New Point(e.X, e.Y))
DestinationNode = CType(sender, TreeView).GetNodeAt(pt)
If IsDropAllowed(OriginalNode, DestinationNode) Then
OriginalRow = CType(OriginalNode, DomainNode).DomainRow
DestinationRow = CType(DestinationNode, DomainNode).DomainRow
OriginalRow.Item("ParentDomID") = DestinationRow.Item("ID")
DestinationNode.Nodes.Add(OriginalNode.Clone)
' Expand the parent node when adding the new node so that the drop
' is obvious. Without this, only a + symbol would appear.
DestinationNode.Expand()
OriginalNode.Remove()
End If