I need to handle some behaviour requiring to identify the grid's row and column index for a given point on the screen (like mouse coordinates).
Given a System.Drawing.Point corresponding to mouse coordinates, how can I retrieve the grid's row and column index?
Just use the built-in methods, each taking a coordinate.
Example, get the clicked cell in an overridden MouseDown
event:
protected override void OnMouseDown(MouseEventArgs e)
{
Int32 row = RowContaining(e.Y);
Int32 col = ColContaining(e.X);
}
Or, if you have a reference to the grid, the same thought applies:
Int32 row = Grid.RowContaining(yCoord);
Int32 col = Grid.ColContaining(xCoord);
You can also use the Point
with ComponentOne's PointAt
method to identify the clicked region:
C1.Win.C1TrueDBGrid.PointAtEnum ptEnum - Grid.PointAt(e.X, e.Y);