RadTreeNode.Clone() causes TypeException

2 posts, 0 answers
  1. Mike
    Mike avatar
    14 posts
    Member since:
    Mar 2008

    Posted 03 Dec 2008 Link to this post

    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:

  2. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 04 Dec 2008 Link to this post

    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. :)
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top