一、说明
使用dev控件,TreeList1向TreeList2拖拽
二、属性
//允许拖拽
treeList1.AllowDrop = true;
treeList2.AllowDrop = true;
//允许多行选择
treeList1.OptionsSelection.MultiSelect = true;
三、代码
#region tree拖拽操作 TreeListHitInfo downHitInfo = null;
#region 拖出
private void treeList1_MouseMove(object sender, MouseEventArgs e)
{
TreeList treelist = sender as TreeList;
if (e.Button == MouseButtons.Left && downHitInfo != null)
{
if (treeList1.Selection.Count == )
return;
Size dragSize = SystemInformation.DragSize;
Rectangle dragRect = new Rectangle(new Point(downHitInfo.MousePoint.X - dragSize.Width / ,
downHitInfo.MousePoint.Y - dragSize.Height / ), dragSize); if (!dragRect.Contains(new Point(e.X, e.Y)))
{
List<TreeListNode> node = new List<TreeListNode>();
foreach (TreeListNode n in treeList1.Selection)
{
node.Add(n);
}
treelist.DoDragDrop(downHitInfo.Node, DragDropEffects.Move);
downHitInfo = null;
DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;
}
} } private void treeList1_MouseDown(object sender, MouseEventArgs e)
{
TreeList treelist = sender as TreeList;
downHitInfo = null;
TreeListHitInfo hitInfo = treelist.CalcHitInfo(new Point(e.X, e.Y)); if (Control.ModifierKeys != Keys.None) return;
if (e.Button == MouseButtons.Left)
{
downHitInfo = hitInfo;
}
} #endregion #region 拖入
private void treeList2_DragOver(object sender, DragEventArgs e)
{
TreeList treelist = sender as TreeList;
if (treelist != null)
{
e.Effect = DragDropEffects.Move;
}
} private void treeList2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
} private void treeList2_DragDrop(object sender, DragEventArgs e)
{
List<TreeListNode> nodes = e.Data.GetData(typeof(List<TreeListNode>)) as List<TreeListNode>;
TreeList grid = sender as TreeList;
DataTable table = grid.DataSource as DataTable; if (nodes != null && nodes.Count > && table != null)
{
foreach (TreeListNode node in nodes)
{
treeList1.Nodes.Add(node);
}
}
}
#endregion
#endregion