Programming Guide : Working with Arrays, Table Fields, and Collections : Table Field Operations : How You Can Scroll to a Specific Row
 
Share this page          
How You Can Scroll to a Specific Row
There are two ways to allow direct scrolling to a particular row:
The SetInputFocus method of the TableField system class
The ActiveRow attribute of the TableField system class
In addition, you can use ArrayObject's Find method to provide the user with the opportunity to specify a row for scrolling. After the user specifies the row, use the SetInputFocus method or the ActiveRow attribute to scroll the table field to the desired row.
How You Can Use the SetInputFocus Method to Scroll
You can use the SetInputFocus method to set the input focus of a frame to a specific cell of a table field. Its syntax is:
integer = tablefield.SetInputFocus([row=integer], [column=varchar(256)])
row
Identifies the row in the array to which to move the input focus
Default: row 1
column
Identifies the name of the column in the table field to which to move the input focus
Default: the first displayed column
The SetInputFocus method returns ER_OK (value of 0) if the parameters are valid, and it returns a nonzero number if there is an error.
When you use the SetInputFocus method, the change in focus occurs at the end of the current event block. The method triggers any appropriate Exit, SetValue, and Entry events. For example, the following event block accepts a number as input from the user and then scrolls the table field display to that row:
declare
  resp = varchar(80);

...
on click menu_button.ChangeRow =
begin
  resp = prompt 'Enter the number of the row '+
    'you want to see.';
  status = field(custtable).SetInputFocus(row =
      int4(resp));
  ...
end;
When you use the SetInputFocus method to specify a column, the column name must be quoted or contained in a varchar variable.
How You Can Use the ActiveRow Attribute to Scroll
The ActiveRow attribute identifies the array row that has the current input focus. If you set this attribute directly, OpenROAD scrolls the data display to the specified row, moves the input focus to the first Landable field in that row, and sets the CurRow attribute to the same specified number.
Setting ActiveRow attribute has no immediate effect. Instead, an internal event is queued that ultimately generates any necessary SetValue and Exit events as the focus attempts to move. To prevent getting incorrect results, therefore, do not set the ActiveRow attribute in an event block and then attempt to use its value in the same event block.
How You Can Scroll Indirectly with the Find Method
You can use the Find method of the ArrayObject class to find the row you want to scroll to, followed by setting ActiveRow to that row to do the actual scrolling.