* BaseGrid.m_Position_Active_Row() * * OVERVIEW: Repositions the active row on the grid to the top of the * grid or to the row specified in the parameter. Adapted * from Atkins, Kramik and Schummer, "MegaFox", p. 16-17. * * PARAMETERS: * * tnRow The offset from the top of the grid specifying the * grid row to which to position the active record. * Default is zero ( No offset or "top row" ). * * If "C" or "c" is passed, the active row is placed * at the horizontal center of the grid * * SYNTAX: BaseGrid.m_Position_Active_Row() * Positions the active row at top of the grid * * BaseGrid.m_Position_Active_Row( 4 ) * Positions the active row at the 5th row. * * BaseGrid.m_Move_Active_Row( "C" ) * Positions the active row at the horizontal center of * the grid. * LPARAMETERS tnRow LOCAL lnCount, lnFieldHeight, lnOldGridHeight, llOldLockScreen, lnOldSelect, ; lnRecNo, lnRow, lnRowCount lnOldSelect = SELECT() WITH thisform * See if the recordsource has any records. If it has no records, just * return. There is nothing to position. SELECT ( this.RecordSource ) COUNT NEXT 1 TO lnCount IF lnCount = 0 RETURN ENDIF * Hide all screen changes from the user until the end of this method. llOldLockScreen = .LockScreen .LockScreen = .T. WITH this lnFieldHeight = ; .Height - .HeaderHeight - ; IIF( INLIST( .ScrollBars, 1, 3 ), SYSMETRIC( 8 ), 0 ) lnRowCount = ; INT( lnFieldHeight / .RowHeight ) DO CASE CASE EMPTY( tnRow ) lnRow = 0 CASE VARTYPE( tnRow ) = "C" .AND. UPPER( tnRow ) = "C" * Position the active row at horizontal center. lnRow = ( INT( lnRowCount / 2 ) - 1 ) CASE VARTYPE( tnRow ) = "N" lnRow = tnRow - 1 ENDCASE lnRow = MAX( 0, MIN( lnRow, lnRowCount - 1 ) ) * Save the current record point position in the grid * then move the record pointer in the grid until the * pointer points to the topmost displayed record. * This may or may not be the first record in the recordsource. lnRecNo = RECNO( .RecordSource ) * Try to skip back lnRow records. SKIP ( lnRow * ( -1 ) ) IN ( .RecordSource ) * If we reached BOF(), go back to the original record * and skip back one record at at time until BOF() is * reached. IF BOF( .RecordSource ) GOTO lnRecNo IN ( .RecordSource ) FOR lnI = 1 TO lnRow - 1 IF BOF( .RecordSource ) EXIT ENDIF SKIP -1 NEXT ENDIF * Capture the height of the grid to be restored below lnOldGridHeight = .Height * Reset the grid height so that only one row is "visible". This * has the effect of moving the active row to the top of the grid. * SYSMETRIC( 8 ) returns the "height of scroll arrows on horizontal scroll bar" * which is also the height of the scroll bar. .Height = .HeaderHeight + .RowHeight + ; IIF( INLIST( .ScrollBars, 1, 3 ), SYSMETRIC( 8 ), 0 ) + 1 * Refresh the grid to reset the recordsource. This puts the * current record in .RecordSource at top row of the grid. .Refresh() * Reset the grid height back to its original height so all of the * rows are once again displayed. .Height = lnOldGridHeight * Go back to the record in .RecordSource for the CurrentActiveRow. GOTO lnRecNo IN ( .RecordSource ) * Setting focus to the grid repaints it so any dynamic coloration is reimposed. .SetFocus() ENDWITH && the Grid .LockScreen = llOldLockScreen ENDWITH && the Form SELECT ( lnOldSelect ) RETURNRegards,