首页 > 代码库 > dev TreeList拖拽
dev TreeList拖拽
一、说明
使用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 == 0) return; Size dragSize = SystemInformation.DragSize; Rectangle dragRect = new Rectangle(new Point(downHitInfo.MousePoint.X - dragSize.Width / 2, downHitInfo.MousePoint.Y - dragSize.Height / 2), 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 > 0 && table != null) { foreach (TreeListNode node in nodes) { treeList1.Nodes.Add(node); } } } #endregion #endregion
dev TreeList拖拽
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。