DevExpress 从一个XtraGridControl 拖拽行到另外一个

using DevExpress.XtraGrid;

using DevExpress.XtraGrid.Views.Base;

using DevExpress.XtraGrid.Views.Grid;

using DevExpress.XtraGrid.Views.Grid.ViewInfo;



GridHitInfo downHitInfo = null;



private void view_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {

    GridView view = sender as GridView;

    downHitInfo = null;

    GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y));

    if(Control.ModifierKeys != Keys.None) return;

    if(e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)

        downHitInfo = hitInfo;

}



private void view_MouseMove(object sender, System.Windows.Forms.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))) {

            DataRow row = view.GetDataRow(downHitInfo.RowHandle);

            view.GridControl.DoDragDrop(row, DragDropEffects.Move);

            downHitInfo = null;

            DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;

        }

    }

}

你可能感兴趣的:(DevExpress 从一个XtraGridControl 拖拽行到另外一个)