Skip to main content

TcxCustomGridTableView.OnCanSelectRecord Event

Occurs before selecting a grid record.

Declaration

property OnCanSelectRecord: TcxGridAllowRecordOperationEvent read; write;

Remarks

The OnCanSelectRecord event is fired only when the View’s OptionsSelection.MultiSelect property is set to True. Use this event to control record selection. The Sender parameter identifies the affected View and the ARecord parameter specifies the record to be selected. To enable record selection, set the AAllow parameter to True. This adds the current record to the collection of selected records.

Indexed access to selected records in default loading mode (when the GridMode property is set to False) is provided by the View’s Controller.SelectedRecords property. When grid mode is applied, see the View’s DataController.GetSelectedBookmark function to obtain selected records. While in grid mode, don’t use the ARecord parameter to refer to the record being selected. Instead, use the bound dataset to access its values.

If the OnCanSelectRecord event handler sets AAllow to False, records will not be selected. However, OnCanSelectRecord does not allow you to prevent record focusing.

The following example disables selection of a record if its tvItemsSTATUS field denotes the ‘Fixed’ string. The value displayed by the item is determined by the indexed DisplayTexts property.

procedure TForm1.tvItemsCanSelectRecord(Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; var AAllow: Boolean);
begin
  if ARecord.DisplayTexts[tvItemsSTATUS.Index] = 'Fixed' then
    AAllow := False;
end;
See Also