Skip to main content
A newer version of this page is available. .

Focused/Selected Records

  • 5 minutes to read

All Table, Card, and Layout Views allow an end-user to navigate through the corresponding dataset’s records (move focus from one record to another). Only a single record can be focused within a View at a time. In (Banded) Table Views, you can focus both data rows and group rows.

When synchronization between a View and a dataset is enabled (in bound mode), the focused record corresponds to the current/active record in the TDataSet. In this case, navigating the dataset via the TDataSet.First, TDataSet.Last, TDataSet.Next, TDataSet.Prior and TDataSet.MoveBy methods changes the focused record’s position.

Synchronization between a grid control and its dataset is enabled when

or

You can get/set the focused record via the View’s Controller.FocusedRecord property. This property specifies an object of the TcxCustomGridRecord class which enables you to:

  • get the data provided by specific record fields (the Values property);

  • expand/collapse the row via the Expanded attribute (only for master and group rows in a (Banded) Table View);

  • select a record via the Selected property (if multi-selection is enabled; see below).

To change the focused record’s position via code, you can use the methods provided by a View’s controller and the data controller’s methods: GotoFirst, GotoLast, GotoNext and GotoPrev.

These methods let you move focus through the current View’s potentially visible data records and grouping rows (i.e. currently visible or available by scrolling). They do not allow you to move focus to records hidden within a collapsed group.

Unlike the data controller’s methods, the controller’s GoToNext and GoToPrev methods enable you to move focus between master and detail Views.

To move focus to data records (even to those that are hidden within collapsed groups) in bound mode, you can use the methods implemented by TDataSet descendants (First, Last, Next, Prior and MoveBy).

Records displayed within a View are indexed. All data records are assigned record indexes defining the order of the records in a dataset. All visible records (including group rows) are assigned indexes (in the data controller, they are called row indexes) and they define the order in which records are displayed on the screen.

The controller’s FocusedRecordIndex property specifies the index of the focused record. You can also use this property to change the focused record. The Controller.FocusedRecordIndex property is equivalent to the data controller’s FocusedRowIndex property.

Note

Do not confuse the View’s Controller.FocusedRecordIndex and DataController.FocusedRecordIndex properties. The former specifies the row index of the focused record, i.e. the record’s visual position (this is equivalent to the Index property of the Controller.FocusedRecord object and to the TcxCustomDataController.FocusedRowIndex property). The latter specifies the record index of the focused record, i.e. the position of the record in the data controller/dataset (this is equivalent to the RecordIndex property of the Controller.FocusedRecord object).

To move focus to a record hidden within a collapsed group, its index (row index) needs to be obtained by using the GetRowIndexByRecordIndex method. It returns the visual position of the record based on its record index. Then assign the obtained index to the Controller.FocusedRecordIndex property.

When a grid control loads all dataset records into memory (the GridMode property is set to False), the FocusedRecordIndex property manages the index of the focused record relative to the first View record.

In grid mode, only a fixed amount of records are loaded into a memory buffer at a time. When scrolling causes a different set of records to be loaded into the buffer, record focus is automatically moved so that it remains on a buffered record (the FocusedRecord property always maintains a record within this buffer). In grid mode, the FocusedRecordIndex property stores a record index relative to the first record of the current visible buffer.

Selected records

ExpressQuantumGrid allows you to select multiple records if the View’s OptionsSelection.MultiSelect property is set to True. When this option is enabled an end-user can select records by clicking them while holding down the Ctrl and Shift keys. The Ctrl key allows you to select/unselect individual records. The Shift key can be used to select a continuous range of records.

To select/unselect an individual record programmatically, you can use:

Please refer to the Selecting Records topic for details.

If the OptionsSelection.MultiSelect property is set to False, only one record can be selected at a time. In this case, the focused and selected records are equivalent.

When grid mode is not applied, you can use the View’s Controller.SelectedRecords property or the data controller’s GetSelectedRowIndex function to access all records currently selected one by one.

In grid mode, you should use the View’s DataController.GetSelectedBookmark function instead.

The data controller provides the ForEachRow method, which allows you to iterate through selected records in all loading modes.

The number of selected records is returned by the Controller.SelectedRecordCount property. A grid control provides methods to clear the selection and delete the selected records. These are found in the View’s Controller object:

Selected records within (Banded) Table Views are marked by a small dot displayed in the indicator panel (set the View’s OptionsView.Indicator property to True to make it visible). It is possible to specify a distinct style for selected records via the View’s Styles.Selection property.

See Also