Our solution is looking to clone items from a master list into a new list. We have this working on the server side but would like to move it client side if it is possible so we can prevent round trips taken.
protected
void
HandleDrop(
object
sender, RadTreeNodeDragDropEventArgs e)
{
RadTreeNode sourceNode = e.SourceDragNode;
RadTreeNode destNode = e.DestDragNode;
RadTreeViewDropPosition dropPosition = e.DropPosition;
//var currentlesson = sourceNode.Value;
//RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
if
(destNode !=
null
)
{
if
(sourceNode.TreeView.SelectedNodes.Count <= 1)
{
var currentlesson = sourceNode.Value;
RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
//this checks if node already exists in new list
if
(foundNode ==
null
)
{
int
? index = PerformDragAndDrop(dropPosition, sourceNode, destNode);
if
(index !=
null
)
{
//Console.Error.WriteLine("NodeDrop: " + e.SourceDragNode.Text + " to " + e.DestDragNode.Text);
//var currentindex = e.SourceDragNode.Index;
var currentindex = index;
var objectid = e.SourceDragNode.Value;
var parentid = destNode.Value;
var parentid2 =
"Newlist"
;
var action =
"moved"
;
if
(parentid.Contains(
"LN"
))
{
EventMovement.Add(action + currentindex +
","
+ objectid +
","
+ parentid2);
result.Text += action +
","
+ currentindex +
","
+ objectid +
","
+ parentid2 + Environment.NewLine;
}
else
{
EventMovement.Add(action + currentindex +
","
+ objectid +
","
+ parentid);
result.Text += action +
","
+ currentindex +
","
+ objectid +
","
+ parentid + Environment.NewLine;
}
}
}
}
else
if
(sourceNode.TreeView.SelectedNodes.Count > 1)
{
int
? index = PerformDragAndDrop(dropPosition, sourceNode, destNode);
if
(index !=
null
)
{
foreach
(RadTreeNode currentNode
in
sourceNode.TreeView.SelectedNodes)
{
var currentlesson = currentNode.Value;
RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
//this checks if node already exists in new list
if
(foundNode ==
null
)
{
PerformDragAndDrop(dropPosition, currentNode, destNode);
//Console.Error.WriteLine("NodeDrop: " + currentNode.Text + " to " + e.DestDragNode.Text);
var currentindex = index;
var objectid = currentNode.Value;
var parentid = destNode.Value;
var action =
"group-moved"
;
EventMovement.Add(currentindex +
","
+ objectid +
","
+ parentid);
result.Text += action +
","
+ currentindex +
","
+ objectid +
","
+ parentid + Environment.NewLine;
}
}
}
}
destNode.Expanded =
true
;
}
}
private
int
? PerformDragAndDrop(RadTreeViewDropPosition dropPosition, RadTreeNode sourceNode, RadTreeNode destNode)
{
int
? index =
null
;
if
(sourceNode.Equals(destNode) || sourceNode.IsAncestorOf(destNode))
{
return
null
;
}
// clone the sourceNode
List<RadTreeNode> sourceNodeClone = CloneNode(sourceNode);
if
(remove ==
false
)
{
sourceNode.Owner.Nodes.Remove(sourceNode);
}
// add source node as a child of the destination node
//if (!sourceNode.IsAncestorOf(destNode))
//{
// destNode.Nodes.Add(sourceNodeClone);
// sourceNodeClone.AllowDrop = false;
//}
// this prevents items from being added as children when moved
switch
(dropPosition)
{
case
RadTreeViewDropPosition.Over:
// child
if
(!sourceNode.IsAncestorOf(destNode))
{
foreach
(RadTreeNode node
in
sourceNodeClone)
destNode.Nodes.Add(node);
}
break
;
case
RadTreeViewDropPosition.Above:
// sibling - above
foreach
(RadTreeNode node
in
sourceNodeClone)
destNode.InsertBefore(node);
break
;
case
RadTreeViewDropPosition.Below:
// sibling - below
foreach
(RadTreeNode node
in
sourceNodeClone)
destNode.InsertAfter(node);
break
;
}
var currentlesson = sourceNode.Value;
RadTreeNode foundNode = RadTreeView2.FindNodeByValue(currentlesson);
if
(foundNode !=
null
)
{
index = foundNode.Index;
}
return
index;
}
private
List<RadTreeNode> CloneNode(RadTreeNode sourceNode)
{
List<RadTreeNode> clonedNode =
new
List<RadTreeNode>();
RadTreeNode clone =
new
RadTreeNode();
clone.Text = sourceNode.Text;
clone.Value = sourceNode.Value;
clone.ImageUrl = sourceNode.ImageUrl;
clone.ExpandedImageUrl = sourceNode.ExpandedImageUrl;
clone.AllowDrop = sourceNode.AllowDrop;
//this carries over the allow drop from the main list
//check if parent node -- for each statement didnt work here
if
(sourceNode.ParentNode !=
null
)
{
if
(sourceNode.Nodes.Count > 0)
{
//grab and move children too
for
(
int
i = 0; i < sourceNode.Nodes.Count - 1; i++)
{
clone.Nodes.Add(sourceNode.Nodes[i]);
}
}
}
clonedNode.Add(clone);
return
clonedNode;
}