protected override void OnMouseClick(GLMouseEventArgs e) { base.OnMouseClick(e); GLDataGridView dgv = Parent as GLDataGridView; var g = GridRowCol(e.Location); if (e.Button == GLMouseEventArgs.MouseButtons.Left) { if (lastselectionstart == lastselectionend) { if (g != null) { var orgbounds = e.Bounds; var orgbloc = e.BoundsLocation; var orgloc = e.Location; var newcell = CellPara(g, e); // may return null if cell not there newcell?.OnMouseCellClick(e); if (e.Handled == false) // and if it did not, call global click { e.Bounds = orgbounds; e.BoundsLocation = orgbloc; e.Location = orgloc; MouseClickOnGrid(g.Row, g.Column, e); } } else { MouseClickOnGrid(-1, -1, e); } } } else if (e.Button == GLMouseEventArgs.MouseButtons.Right) { if (dgv.ContextMenuGrid != null) { if (g == null) // out of cell, return pos of click { g = new GLDataGridView.RowColPos() { Column = -1, Row = -1, Location = e.Location } } ; else { if (dgv.SelectRowOnRightClick) { dgv.Rows[g.Row].Selected = true; } } dgv.ContextMenuGrid.Show(FindDisplay(), e.ScreenCoord, opentag: g); } } }
// Get the cell from the rowcolpos, and set event args private GLDataGridViewCell CellPara(GLDataGridView.RowColPos g, GLMouseEventArgs e) { GLDataGridView dgv = Parent as GLDataGridView; if (g.Column < dgv.Rows[g.Row].CellCount) { var newcell = dgv.Rows[g.Row].Cells[g.Column]; e.Bounds = new Rectangle(g.CellLocation.X, g.CellLocation.Y, dgv.Columns[g.Column].Width, dgv.Rows[g.Row].Height); e.BoundsLocation = g.Location; e.Location = new Point(g.Location.X - newcell.Style.Padding.Left, g.Location.Y - newcell.Style.Padding.Top); return(newcell); } else { return(null); } }