473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

treenode.clone method

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
--
Please take out the garbage before using reply address.

Nov 20 '05 #1
2 4448
Hi Bob,

I can not reproduce the problem with the code below.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To 7
Me.TreeView1.Nodes.Add("Hello" + i.ToString())
Next
Me.TreeView1.Nodes(7).Nodes.Add("Test")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim lastNode As TreeNode
lastNode = TreeView1.Nodes(TreeView1.Nodes.Count -
1).Nodes(TreeView1.Nodes(TreeView1.Nodes.Count - 1).Nodes.Count - 1)
' Clone the last child node.
Dim clonedNode As TreeNode = CType(lastNode.Clone(), TreeNode)
' Insert the cloned node as the first root node.
TreeView1.Nodes.Insert(0, clonedNode)
MessageBox.Show(lastNode.Text & _
" tree node cloned and added to " & TreeView1.Nodes(0).Text)
End Sub

Also you may try to check if you have another class named TreeNode.
I think you may try to declare the TreeNode as below
System.Windows.Forms.TreeNode instead of TreeNode.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
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
Peter Huang wrote:
Hi Bob,

I can not reproduce the problem with the code below.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To 7
Me.TreeView1.Nodes.Add("Hello" + i.ToString())
Next
Me.TreeView1.Nodes(7).Nodes.Add("Test")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim lastNode As TreeNode
lastNode = TreeView1.Nodes(TreeView1.Nodes.Count -
1).Nodes(TreeView1.Nodes(TreeView1.Nodes.Count - 1).Nodes.Count - 1)
' Clone the last child node.
Dim clonedNode As TreeNode = CType(lastNode.Clone(), TreeNode)
' Insert the cloned node as the first root node.
TreeView1.Nodes.Insert(0, clonedNode)
MessageBox.Show(lastNode.Text & _
" tree node cloned and added to " & TreeView1.Nodes(0).Text)
End Sub

Also you may try to check if you have another class named TreeNode.
I think you may try to declare the TreeNode as below
System.Windows.Forms.TreeNode instead of TreeNode.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--
Please take out the garbage before using reply address.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some...
3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
8
by: kurotsuke | last post by:
Hi, I need to clone a class (called NodeAbstract) that I derived from TreeNode. I need to clone it to support drag and drop on the treeview. I tried to use the MemberWiseClone (in my own...
0
by: Richard | last post by:
I need a deep clone of my derived TreeNode class. Can anyone help me writting a clone() override that will do this?
0
by: Richard | last post by:
I need a deep clone of my derived TreeNode class. Can anyone help me writting a clone() override that will do this? I've seen examples like this,...
2
by: The Kiddie | last post by:
Hi Guys, I am doing some work with a treenode and I want to record the selected item, and it may change while the user is performing some tasks and I need to know which one was originally...
4
by: Turban | last post by:
When I attempt to run the following code: protected void NavigationTreeView_TreeNodePopulate(object sender, TreeNodeEventArgs e) { TreeNode tn1 = new TreeNode("node1","node1"); TreeNode tn2 =...
1
by: voiger | last post by:
Hello all! I need to move a TreeNode with significant amount of subnodes to another parent node. I use TreeNode.Clone(), add a new cloned node to the destination node, and than I TreeNode.Remove()...
2
by: dutsnekcirf | last post by:
I found this article on how to nudge the treenode items up or down in the order of a treeview control. The problem is it's in C# and I know nothing about C#. In fact, C# scares me (I think it's the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.