Event to change the selected cell color

I have a TAdvStringGrid linked to virtual data in a TObjectList. I attached a GetCellColor event and in there check a flag for the row's data record and change the font color accordingly.  This works.  However the selected cell color is not affected.

How can I change a cell's selected and non-selected font color based on virtual data?

My exact code:

procedure TMainForm.AdvStringGrid1GetCellColor(Sender: TObject; ARow,
  ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
  if ARow > 0 then
    if not FNewRequest.CanReturnHistory(ARow - 1) then
      AFont.Color := clLtGray;

The font color in selected cells is set with grid.SelectionTextColor.
By default, this color is used for selected cells. If you always want to override this by the event OnGetCellColor, set grid.SelectionTextColor = clNone.

1 Like