treenode.clone method

B

bclegg

Hi,
When I implement the example code it errors with
'No parameterless constructor defined for this object.'

experimenting with dim o as object = mytreenode.clone() gives the same
error.

The example code is:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim lastNode As TreeNode
lastNode = tvAvailable.Nodes(tvAvailable.Nodes.Count - 1). _
Nodes(tvAvailable.Nodes(tvAvailable.Nodes.Count -
1).Nodes.Count - 1)

' Clone the last child node.
Dim clonedNode As TreeNode = CType(lastNode.Clone(),
TreeNode)******Error HERE**************

' Insert the cloned node as the first root node.
tvAvailable.Nodes.Insert(0, clonedNode)
MessageBox.Show(lastNode.Text & _
" tree node cloned and added to " & tvAvailable.Nodes(0).Text)

End Sub

Is this method flawed? Does anybody have working code for copying a
treenode from one tree to another?
Thanks
Bob
 
B

bclegg

Hi Peter,
Problem solved.
Your code pointed the way.
My tree view had a root node which was a derived class and had no
parameterless constructor.
Thanks
Bob
 

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

Top