Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TcxDBDataController.LocateByKey(Variant) Method

Finds and focuses the record containing the specified key field values.

#Declaration

Delphi
function LocateByKey(const AKeyFieldValues: Variant): Boolean;

#Parameters

Name Type
AKeyFieldValues Variant

#Returns

Type
Boolean

#Remarks

This function locates the record with the specified key field value(s). The AKeyFieldValues parameter should specify a variant or an array of variant values corresponding to the key field(s) set via the KeyFieldNames property.

The function returns True when the appropriate record is found and focused (in ExpressQuantumGrid, the view’s OnFocusedRecordChanged event is fired when changing the focused record). If the record doesn’t exist or no key field names are assigned, LocateByKey returns False.

The LocateByKey function does not force the reloading of dataset data, since it searches its internal buffer. The dataset’s Locate method also allows you to locate records with specific criteria. However, each call of Locate forces the data controller to reload data from the dataset, thus slowing down performance, especially for large datasets. To prevent data reloading when moving the cursor within the dataset, you can enclose call(s) to Locate within the BeginLocate and EndLocate methods.

See Also