private void DGV_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { int mousCol = DGV.HitTest(e.X, e.Y).ColumnIndex; int mousRow = DGV.HitTest(e.X, e.Y).RowIndex; if (mousCol == 5 && DGV.SelectedCells.Count == 1 && DGV.SelectedCells[0].ColumnIndex == 5 && DGV.SelectedCells[0].RowIndex == mousRow) { DateMenu.Show(Cursor.Position); MouseX = e.X; MouseY = e.Y; MouseRow = DGV.HitTest(e.X, e.Y).RowIndex; } if (mousCol == -1 && DGV.SelectedRows.Count == 1 && DGV.SelectedRows[0].Index == mousRow) { menu.Show(Cursor.Position); MouseX = e.X; MouseY = e.Y; MouseRow = DGV.HitTest(e.X, e.Y).RowIndex; DGV.Rows[MouseRow].Selected = true; } if (mousCol == 0 && DGV.SelectedCells.Count == 1 && DGV.SelectedCells[0].ColumnIndex == 0 && DGV.SelectedCells[0].RowIndex == mousRow) { NameMenu.Show(Cursor.Position); MouseX = e.X; MouseY = e.Y; MouseRow = DGV.HitTest(e.X, e.Y).RowIndex; } } }
private void DGV_DragOver(object sender, DragEventArgs e) { var pt = DGV.PointToClient(new Point(e.X, e.Y)); var ht = DGV.HitTest(pt.X, pt.Y); if ((0 <= ht.RowIndex) && (e.Data.GetData(typeof(DownloadRow)) is DownloadRow row) && (row.GetVisibleIndex() != ht.RowIndex)) { e.Effect = e.AllowedEffect; if (_DragOver_RowIndex != ht.RowIndex) { _DragOver_RowIndex = ht.RowIndex; DGV.Invalidate(); } ScrollIfNeed(in pt); return; } e.Effect = DragDropEffects.None; if (_DragOver_RowIndex.HasValue) { _DragOver_RowIndex = null; DGV.Invalidate(); } ScrollIfNeed(in pt); }
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; } }
private void DGV_MouseDown(object sender, MouseEventArgs e) { _DGV_MouseDown_HitTestInfo = DGV.HitTest(e.X, e.Y); if (e.Button == MouseButtons.Left) { _DGV_MouseDown_ButtonLeft_Location = e.Location; } }
private void DGV_MouseDown(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Right) { var hti = DGV.HitTest(e.X, e.Y); DGV.CurrentCell = DGV.Rows[hti.RowIndex].Cells[hti.ColumnIndex]; } } catch { } }
private void DGV_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContextMenu m = new ContextMenu(); int currentMouseOverRow = DGV.HitTest(e.X, e.Y).RowIndex; if (currentMouseOverRow >= 0) { m.MenuItems.Add(new MenuItem("Visualizar Documento", new EventHandler(VisualizarDocumento))); m.MenuItems.Add(new MenuItem("Liquidar Documento", new EventHandler(LiquidarDocumewnto))); } m.Show(DGV, new Point(e.X, e.Y)); } }
private void DGV_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetData(typeof(DownloadRow)) is DownloadRow row) { var pt = DGV.PointToClient(new Point(e.X, e.Y)); var ht = DGV.HitTest(pt.X, pt.Y); if ((0 <= ht.RowIndex) && (row.GetVisibleIndex() != ht.RowIndex)) { _Model.ChangeRowPosition(row, ht.RowIndex); e.Effect = e.AllowedEffect; return; } } e.Effect = DragDropEffects.None; }
private void DGV_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContextMenu m = new ContextMenu(); //m.MenuItems.Add(new MenuItem("Cut")); //m.MenuItems.Add(new MenuItem("Copy")); //m.MenuItems.Add(new MenuItem("Paste")); int currentMouseOverRow = DGV.HitTest(e.X, e.Y).RowIndex; if (currentMouseOverRow >= 0) { //m.MenuItems.Add(new MenuItem(string.Format("Do something to row {0}", currentMouseOverRow.ToString()))); m.MenuItems.Add(new MenuItem("Ver Documento", new EventHandler(VerDocumento))); } m.Show(DGV, new Point(e.X, e.Y)); } }
private void DGV_SelectionChanged(object sender, EventArgs e) { _UserMade_DGV_SelectionChanged = true; var selectedDownloadRow = this.GetSelectedDownloadRow(); SelectionChanged?.Invoke(selectedDownloadRow); if ((selectedDownloadRow != null) && !selectedDownloadRow.IsFinished()) { var pt = DGV.PointToClient(Control.MousePosition); var ht = DGV.HitTest(pt.X, pt.Y); switch (ht.ColumnIndex) { case OUTPUTFILENAME_COLUMN_INDEX: case OUTPUTDIRECTORY_COLUMN_INDEX: DGV.SetHandCursorIfNonHand(); break; } } }
private void DGV_MouseClick(object sender, MouseEventArgs e) { var ht = DGV.HitTest(e.X, e.Y); if (0 <= ht.RowIndex) { var allowed = (_DGV_MouseDown_HitTestInfo.RowIndex == ht.RowIndex) && ((_DGV_MouseDown_HitTestInfo.Type == DataGridViewHitTestType.Cell) || (_DGV_MouseDown_HitTestInfo.Type == DataGridViewHitTestType.RowHeader)); if (allowed) { DGV.Rows[ht.RowIndex].Selected = true; if (e.Button == MouseButtons.Right) { MouseClickRightButton?.Invoke(e, GetSelectedDownloadRow()); } } } else if ((ht.Type == DataGridViewHitTestType.None) || (ht.Type == DataGridViewHitTestType.Cell)) { switch (e.Button) { case MouseButtons.Left: if (_DGV_MouseDown_HitTestInfo.Type == DataGridViewHitTestType.None) { DGV.ClearSelection(); } break; case MouseButtons.Right: MouseClickRightButton?.Invoke(e, null); break; } } }