代码改变世界

DevExpress WinForm GridControl 实现拖动多行到TreeView

2015-04-23 17:18  张小驴同学  阅读(1176)  评论(0编辑  收藏  举报

 

参考文章:Drag-and-drop of multiple selected grid rows

 

如果列表有使用行内编辑功能,需要将列表的 OptionsBehavior.EditorShowMode 属性设置为 MouseUp 或者 Click

 

        
    
       private GridHitInfo downHitInfo = null;
     private void myView_MouseDown(object sender, MouseEventArgs e) { GridView view = sender as GridView; downHitInfo = null; if (view != null) { GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y)); if (e.Button == MouseButtons.Left && hitInfo.InRow && hitInfo.HitTest != GridHitTest.RowIndicator) { downHitInfo = hitInfo; } } } private void myView_MouseMove(object sender, MouseEventArgs e) { GridView view = sender as GridView; if (e.Button == MouseButtons.Left && downHitInfo != null) { Size dragSize = SystemInformation.DragSize; Rectangle dragRect = new Rectangle(new Point(downHitInfo.HitPoint.X - dragSize.Width/2,downHitInfo.HitPoint.Y - dragSize.Height/2), dragSize); if (!dragRect.Contains(new Point(e.X, e.Y))) { if (view != null) { List<MyClass> myList = view.GetSelectedRows().Select(rownum => view.GetRow(rownum) as MyClass).ToList(); view.GridControl.DoDragDrop(myList, DragDropEffects.Move); } downHitInfo = null; DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true; } } } private void myTreeView_DragOver(object sender, DragEventArgs e) { e.Effect = e.Data.GetDataPresent(typeof(List<MyClass>)) ? DragDropEffects.Move : DragDropEffects.None; } private void myTreeView_DragDrop(object sender, DragEventArgs e) { List<MyClass> modelData = (List<MyClass>)e.Data.GetData(typeof(List<MyClass>)); TreeNode dropNode = this.myTreeView.GetNodeAt(myTreeView.PointToClient(new Point(e.X, e.Y))); //这里写拖动后想要执行的操作 }