When handling low-level mouse interactions—such as MouseDown or MouseUp events—in TrueDBGrid, standard event arguments only provide the raw pixel coordinates (e.X and e.Y) relative to the control's bounding box. Developers often need to translate these pixel coordinates into the specific row and column indexes of the clicked cell.
Solution
To convert pixel coordinates into cell matrix coordinates, use the grid's RowContaining and ColContaining helper methods inside your mouse event handler.
Before attempting to evaluate the row and column positions, it is good practice to check PointAt(e.X, e.Y) to ensure the user actually clicked inside an active cell area rather than on a scrollbar, group header, or empty region outside the grid. Passing e.Y into RowContaining() returns the clicked row index, while passing e.X into ColContaining() returns the clicked column index.
private void TrueDBGrid_MouseUp(object sender, MouseEventArgs e)
{
var grid = sender as TrueDBGrid;
// Ensure the click occurred over a valid grid area and was a left-click
if (grid != null && grid.PointAt(e.X, e.Y) != PointAtEnum.NotInGrid && e.Button == MouseButtons.Left)
{
// Translate pixel X and Y coordinates to cell Row and Column indexes
int rowIndex = grid.RowContaining(e.Y);
int columnIndex = grid.ColContaining(e.X);
MessageBox.Show($"Clicked Cell Position - Row: {rowIndex}, Column: {columnIndex}");
}
}