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

TcxCustomGridTableViewStyles.OnGetSelectionStyle Event

In This Article

Allows you to change the style applied to a selected record.

#Declaration

Delphi
property OnGetSelectionStyle: TcxGridGetSelectionStyleEvent read; write;

#Remarks

This event occurs every time the TcxGrid control is about to apply a style to a selected row. You can analyze the item type within the OnGetSelectionStyle event handler to apply different formatting to different grid item types:

procedure TfrmGridOnGetSelectionStyle.cxGrid1DBTableView1StylesGetSelectionStyle(Sender: TcxCustomGridTableView;
  ARecord: TcxCustomGridRecord; AItem: TObject; out AStyle: TcxStyle);
var
  ASummaryItem: TcxDataSummaryItem;
begin
  if AItem is TcxGridDBColumn then
    case ARecord.RecordIndex mod 3 of
      0: AStyle := cxStyle1;
      1: AStyle := cxStyle2;
      2: AStyle := cxStyle3;
    end;

  if not ARecord.IsData then
  begin
    case Sender.DataController.DataControllerInfo.DataGroups.RowInfo[ARecord.Index].Index mod 3 of
      0: AStyle := cxStyle1;
      1: AStyle := cxStyle2;
      2: AStyle := cxStyle3;
    end;
  end;

  if AItem is TcxDataSummaryItem then
  begin
    ASummaryItem := AItem as TcxDataSummaryItem;
    if ASummaryItem.Index = 1 then
      AStyle := cxStyle1
    else
      AStyle := cxStyle2
  end;

  if AItem is TcxDataGroupSummaryItems then
    AStyle := cxStyle3;
end;

See Also