We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.

# Get Row/Col of Negative Point

When scrolling the grid, it is possible to get a point with a negative y value when calling the RowColToPoint to method. For example, if I scroll the grid so that row 1 is no longer visible and call this.ViewLayout.RowColToPoint(1, 1, false), I get a point with a negative y value. How can I get the row col values with this point? When I call PointToRowCol(pt,out row, out col) with a point that has a negative y value, I get -1 as the row and column. What is the reverse of RowColToPoint that will work with a point that is off the grid? Thanks, Steve

There is no grid method that does this, so you will have to write your own. Here is a rough try at it. You will probably have to tweak it. It starts at the top and moves down until it finds the right row. You coulf try using a bunary search instead of this linear search if performance is a problem for you.
private int GetRowAtNegY(int y)
{
if(y >= 0 )
return -1;
int y0 = this.gridControl1.ViewLayout.RowColToPoint(1,1, GridCellSizeKind.ActualSize).Y;
if(y0 >= 0)
return -1;
int i = 1;
while(i < this.gridControl1.RowCount && y > y0 + this.gridControl1.RowHeights[i])
{
y0 += this.gridControl1.RowHeights[i];
i++;
}
return i;
}