先获取选中的节点,再处理将节点拖入另一个XtratreeList时的OnDragDrop方法。
关键代码:
private void OnDragEnter(object sender, DragEventArgs e)
{
TreeList list = (TreeList)sender;
TreeListNode node = GetDragNode(e.Data);
if (node != null && node.TreeList != list)
e.Effect = DragDropEffects.Copy;
}
private void OnDragDrop(object sender, DragEventArgs e)
{
TreeListNode node = GetDragNode(e.Data);
if (node == null) return;
TreeList list = (TreeList)sender;
if (list == node.TreeList) return;
TreeListHitInfo info = list.CalcHitInfo(list.PointToClient(new Point(e.X, e.Y)));
InsertBrunch(list, node, info.Node == null ? -1 : info.Node.Id);
}
private void InsertBrunch(TreeList list, TreeListNode node, int parent) {
ArrayList data = new ArrayList();
foreach (TreeListColumn column in node.TreeList.Columns)
data.Add(node[column]);
parent = list.AppendNode(data.ToArray(), parent).Id;
//如果拖拽节点有子节点,将子节点也一起拖入
if (node.HasChildren)
foreach (TreeListNode n in node.Nodes)
InsertBrunch(list, n, parent);
}
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/135.html