Skip to content

MoveToRow - cCJGrid

Attempts to move to the passed row number

Type: Procedure

Parameters

Parameter Type Description
iIndex Integer The row number to move to

Syntax

Procedure MoveToRow Integer iIndex

Call Example

Send MoveToRow iIndex

Description

MoveToRow attempts to navigate to the row passed in iIndex. The row number must exist in your datasource, which means that it must be less than RowCount of phoDataSource. If this is not the case, an unhandled error will occur.

Any time a row change occurs, the grid will check to see if current SelectedRow has changes. If it has changes, that row must be saved or cleared. If pbAutoSave is True, which it usually is, a save will be attempted before the row change. The save is attempted by calling SaveSelectedRow. This function manages a save and may include user verifications and column validations. If the save is cancelled, the row navigation will be cancelled.

If a row is changed and pbAutoSave is false, the grid will attempt to undo the row changes. If the row is a new row, it will undo the changes by removing the row. It does this by calling RemoveNewSelectedRow. If the row is not new, it will undo the changes by restoring the row to its pre-edited state. It does this by calling RestoreSelectedRow. In either case, data loss verifications are sent, which means that the undo can be called, which means that the row change can be cancelled.

With a default cCJGrid, you may not be aware of this underlying process. A row change will consist of a save but there will be no user verification or no column validations. The save will just consist of an internal update of the datasource. From the user's and the developer's perspective, it will just appear that you are changing rows. You can add verifications and validations as needed. In cDbCJGrids, it is more common to see verifications and validations, with validations being provided by your Data Dictionaries.

Upon completion, SelectedRow will be updated. If needed, you can check to see if the navigation succeeded by checking SelectedRow.

// move down 10 rows
Get phoDataSource to hoDataSource
Get SelectedRow of hoDataSource to iSel
Get RowCount of hoDataSource to iRows
Move (iSel + 10) to iSel 
If (iSel>=iRows) Begin
    Move (iRows-1) to iSel
End
Send MoveToRow iSel
Get SelectedRow of hoDataSource to iNewSel
If (iNewSel<>iSel) Begin
    Send Info_Box "Oh no, the move failed"
End

MoveToRow always attempts to make the moved-to row visible and uses its own logic to place the row in a sensible position within the visible grid. You can use this in conjunction with the COM property ComTopRowIndex to exert more control over the positioning of the row. Get ComTopRowIndex will tell you what row is the current top row. Set ComTopRowIndex lets you adjust that top row. You will get different behaviors if you set this before or after sending MoveToRow and you can use these differences to your advantage. The last message sent always takes precedence. If ComTopRowIndex is set before you send MoveToRow, MoveToRow will attempt to position itself without changing the top row index but, if needed, it will adjust the top row index in order to make the moved-to row visible. If ComTopRowIndex is set after you send MoveToRow, the top row will be adjusted it is possible that the moved-to row will be scrolled away and no longer visible.

See Also

MoveDownRow | MoveUpRow | MovePageUp | MovePageDown | MoveToFirstRow | MoveToLastRow