Skip to main content

TcxCustomDataController.ChangeRowSelection(Integer,Boolean) Method

Changes the selection state of a particular row.

Declaration

procedure ChangeRowSelection(ARowIndex: Integer; ASelection: Boolean); virtual;

Parameters

Name Type
ARowIndex Integer
ASelection Boolean

Remarks

A data controller enables you to select and focus rows (data records and grouping rows). There is always one focused row in the data controller, which is controlled by the FocusedRowIndex property.

If the data controller’s MultiSelect property is set to False, there can be only one selected row — the focused row. When you focus a row in this mode, it is automatically selected and the GetSelectedCount method returns 1. However, the SyncSelected method does allow you to unselect the focused row. In this case, GetSelectedCount will return 0.

If the MultiSelect property is set to True, you are able to select multiple rows in the data controller. In this mode, you can use the ChangeRowSelection, SelectRows and SelectAll methods to change row selection states. Changing the selection state of a row does not affect the focused row.

Use the ChangeRowSelection method to specify a row’s selection state (a data record or a grouping row) addressed by the ARowIndex parameter. The ARowIndex parameter defines its row index. To select this row, set ASelection to True. To unselect it, set ASelection to False.

Note

To enable multiple record selection in ExpressQuantumGrid, you can also use the View’s OptionsSelection.MultiSelect property. Changing the OptionsSelection.MultiSelect property sets the data controller’s MultiSelect property.

Let’s consider an example of selecting records within the tvCustomers View in ExpressQuantumGrid. The following code selects records based on the Customer field value. The Customer field is a string field displayed by the tvCustomersCustomer column. We need to select records with the Customer field set to ‘Y’.

To get a row index using a particular record index, the GetRowIndexByRecordIndex method of the View’s data controller is used. Its first parameter provides the record index and the second parameter determines whether the record should be visible if currently hidden under a collapsed group row. The second parameter is set to True, to ensure that the record is visible, thus enabling its selection.

You should use this code only when grid mode is not in effect (the View’s DataController.DataModeController.GridMode property is set to False). In grid mode, you will not be able to process all records using the following code. To navigate records in grid mode, use the members of your TDataSet object (First, Last, Next, Prior and MoveBy).

var
  I: Integer;
//...
  tvCustomers.OptionsSelection.MultiSelect := True;
  with tvCustomers.DataController do
  begin
    ClearSelection();
    for I := 0 to RecordCount - 1 do
    begin
      if Values[I, tvCustomersCustomer.Index] = 'Y' then
        ChangeRowSelection(GetRowIndexByRecordIndex(I, True), True);
    end;
  end;
See Also