TcxCustomGridTableView.OnCanSelectRecord Event
Allows you to prevent a record from being selected.
Declaration
property OnCanSelectRecord: TcxGridAllowRecordOperationEvent read; write;
Remarks
The OnCanSelectRecord
event occurs only when the View’s OptionsSelection.MultiSelect property is set to True
. Handle this event to prevent a record from being selected under specific conditions. The Sender
parameter provides access to the grid View that raised the event, and the ARecord
parameter identifies the record that is about to be selected. To allow record selection, assign True
to the AAllow
parameter.
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 an OnCanSelectRecord
event handler assigns False
to the AAllow
parameter, the processed record does not become selected but input focus can navigate to this record.
The following code example prevents 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;