This is a migrated thread and some comments may be shown as answers.

RadTreeNode.Clone() causes TypeException

1 Answer 73 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 03 Dec 2008, 07:56 PM
I have two radtreeviews on a page and i would like to drag and drop nodes between the two. I have the drag working fine the destination treeview is adding nodes correctly, but the source treeview is DELETING the dragged node. I am trying to CLONE the source node and reinsert it, to prevent the deletion, but when i simply call:

sourceNode.TreeView.Nodes.Insert(sourceNode.Index, sourceNode.Clone());

I receive the following error. How is it possible that the sourceNode does not match the sourceNode in a CLONE()??? We are using the version v 2008.2.1001.35 of the RadAjax controls.

System.Reflection.TargetException was unhandled
  Message="Object does not match target type."
  Source="System"
  StackTrace:
       at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
       at Telerik.Web.UI.RadTreeNode.Clone()
  InnerException:

1 Answer, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 04 Dec 2008, 02:46 PM
Hey Mike,

Alright, after a bit of testing, this appears to be working for what you are looking for...

Basically, anywhere that you see this in the code:

sourceNode.Owner.Nodes.Remove(sourceNode); 

Change it to add this line first, as follows:

sourceNode.InsertBefore(sourceNode.Clone());  
sourceNode.Owner.Nodes.Remove(sourceNode); 

This clones the source, puts it before the current source, then allows the original source to be removed/moved (I tried removing the line blah.remove but it didn't work!).  This way, you create a copy of the node (wherever you are dropping it) but it keeps the original node in its original position.  Checked it with every copy scenario I can imagine on my test page, hopefully works the same for you.

Let me know if that works for you. :)
Tags
TreeView
Asked by
Mike
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Share this question
or