Пример #1
0
        private void DGV_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            var row = GetSelectedDownloadRow();

            if (row == null)
            {
                return;
            }

            var ht = DGV.HitTest(e.X, e.Y);

            if ((ht.RowIndex < 0) || (ht.ColumnIndex < 0))
            {
                return;
            }

            if (_DGV_MouseDown_HitTestInfo.Type != DataGridViewHitTestType.Cell)
            {
                return;
            }

            const int MOVE_DELTA = 5;

            if (Math.Abs(_DGV_MouseDown_ButtonLeft_Location.X - e.X) < MOVE_DELTA &&
                Math.Abs(_DGV_MouseDown_ButtonLeft_Location.Y - e.Y) < MOVE_DELTA)
            {
                return;
            }
            //-----------------------------------------------------//

            _DragOver_RowIndex = null;
            DGV.AllowDrop      = true;
            DGV.DragOver      += DGV_DragOver;
            DGV.DragDrop      += DGV_DragDrop;
            DGV.CellPainting  += DGV_DragDrop_CellPainting;
            try
            {
                var dragDropEffect = DGV.DoDragDrop(row, DragDropEffects.Move);
                if (dragDropEffect == DragDropEffects.Move)
                {
                    SelectDownloadRow(row);
                }
                else
                {
                    DGV.Invalidate();
                }
            }
            finally
            {
                DGV.DragOver     -= DGV_DragOver;
                DGV.DragDrop     -= DGV_DragDrop;
                DGV.CellPainting -= DGV_DragDrop_CellPainting;
                DGV.AllowDrop     = false;
            }
        }