Ivan, thanks for this. Unfortunately this isn't really much better because the combo box items in the user control are all static, and it doesn't really account for copying over any settings from any subnode->nodes or subnode->nodes->nodes... But before you lose any more sleep i wanted to let you know that i think i figured out a way to accomplish my objective. It's a little bit of a PITA but it looks like it works. I'm going to post the relevant code portions here in case anyone else wants to implement similar functionality. However i will repeat my previous comment that this would be so much easier if the Parent property was simply settable. That would make this workaround completely unnecessary and you could accomplish this task w/ a single line of code. Since it's not settable you have to use the approach that Ivan explored using the RadTreeNode.Clone() method to create a copy of the subnodes and then you have to implement your own functionality to copy the correct state of your user control from the old node to the newly cloned node.
So here it is...
if (RadTreeView1.SelectedNode.Nodes.Count > 0)
for (int i = 0; i < RadTreeView1.SelectedNode.Nodes.Count; i++)
RadTreeNode nodeToInsert = RadTreeView1.SelectedNode.Nodes[i].Clone();
if (RadTreeView1.SelectedNode.ParentNode != null)
RadTreeView1.SelectedNode.ParentNode.Nodes.Insert(RadTreeView1.SelectedNode.Index + i, nodeToInsert);
RadTreeView1.Nodes.Insert(RadTreeView1.SelectedNode.Index + i, nodeToInsert);
When you remove a node, and that node contains sub-nodes you include a little for loop to go through each of the sub-nodes.
The RadTreeNode.Clone() method does a good job to clone any further subnodes but it doesn't copy any of the settings or state from your user control (that is being used as the node template). You have to do the copying by hand, which is where:
comes into play. Before i get to the details of that method, i wanted to note that it's important that you call CopyNodeSettings() after you add the node to the correct location in the tree. Calling Nodes.Insert(RadTreeNode) is what triggers your RadTreeNode to have the NodeTemplate (your control) applied. It is here that you can also bind any custom EventHandlers you need for your custom control.
Now, on to CopyNodeSettings(). The two nodes passed into this method contain an identical node structure... i.e. if the current node looks like
then nodeToInsert will also have the same structure, by virtue of having called the clone() method.
CopyNodeSettings looks like this:
private void CopyNodeSettings(RadTreeNode nodeToInsert, RadTreeNode nodeToCopy)
wucExpression wucNew = (wucExpression)nodeToInsert.FindControl("wucExpression1");
wucExpression wucOld = (wucExpression)nodeToCopy.FindControl("wucExpression1");
if (wucNew == null)
//copy settings from wucOld to wucNew until every setting, every control, every value etc is the same..
//i.e. wucNew.MyProperty1 = wucOld.MyProperty1
//i.e. wucNew.MyProperty2 = wucOld.MyProperty2 ...
//if you have dropdown lists, comboboxes whatever you should be able to iterate through old and transfer items / values / selection preferences to new.
//now we need to copy the node settings for each child node, if present, using recursion. we know the nodes map 1-1
for (int i = 0; i < nodeToCopy.Nodes.Count; i++)
Hopefully this makes sense and if anyone else is looking to implement this, it will put you on the correct path. Ivan, thanks for the time you spent trying to help. i do appreciate the effort.