Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

RelativeRow, RelativeColumn

These properties tell you which cell of a grid has focus relative to the current position of the data in the grid.

Usage

nRow = grdGrid.RelativeRow
nCol = grdGrid.RelativeColumn

The values in these properties are counted from the cell currently in the upper-left corner of the grid. Like ActiveRow and ActiveColumn, you can’t change these (use ActivateCell instead); and they reflect ColumnOrder, not the underlying order in the Columns collection.

RelativeColumn can deal with the idea that the column with focus might get scrolled out of the visible part of the grid. If it scrolls off to the right, RelativeColumn just keeps getting bigger. If it scrolls off to the left, RelativeColumn gets negative.

RelativeRow, however, isn't that smart. If the current record isn't visible in the grid, RelativeRow becomes 0. (ActiveRow has the same behavior.)

The combination of RelativeColumn and LeftColumn (LeftColumn + RelativeColumn - 1) always tells you where you are in the grid. Of course, ActiveColumn gives you the same information.

Example

* You might check in the grid's Scrolled event to see if
* the current record has gone offscreen.
IF This.RelativeRow = 0
   * do something to move the record pointer so focus is
   * in the visible area
ENDIF

See Also

ActivateCell, ActiveColumn, ActiveRow, Columns, ColumnCount, LeftColumn