Navigating Records in a Filtered Dataset

From RAD Studio
Jump to: navigation, search

Go Up to Displaying and Editing a Subset of Data Using Filters


There are four dataset methods that navigate among records in a filtered dataset. The following table lists these methods and describes what they do:

Filtered dataset navigational methods :

Method Purpose

FindFirst

Move to the first record that matches the current filter criteria. The search for the first matching record always begins at the first record in the unfiltered dataset.

FindLast

Move to the last record that matches the current filter criteria.

FindNext

Moves from the current record in the filtered dataset to the next one.

FindPrior

Move from the current record in the filtered dataset to the previous one.



For example, the following statement finds the first filtered record in a dataset:

DataSet1.FindFirst;
DataSet1->FindFirst();

Provided that you set the Filter property or create an Data.DB.TDataSet.OnFilterRecord event handler for your application, these methods position the cursor on the specified record regardless of whether filtering is currently enabled. If you call these methods when filtering is not enabled, then they

  • Temporarily enable filtering.
  • Position the cursor on a matching record if one is found.
  • Disable filtering.

Note: If filtering is disabled and you do not set the Filter property or create an OnFilterRecord event handler, these methods do the same thing as First, Last, Next, and Prior.

All navigational filter methods position the cursor on a matching record (if one is found), make that record the current one, and return True. If a matching record is not found, the cursor position is unchanged, and these methods return False. You can check the status of the Found property to wrap these calls, and only take action when Found is True. For example, if the cursor is already on the last matching record in the dataset and you call FindNext, the method returns False, and the current record is unchanged.

See Also