FNCGrid - How to set the background for the current row

I want the selected row to be colored with the same background color to visibly show waht row is current. Is there an option for this? What is the best way to do this?

procedure TForm1.FormCreate(Sender: TObject);
var
  i, j: Integer;
begin
  for i := 0 to TMSFNCGrid1.RowCount - 1 do
  begin
    for j := 0 to TMSFNCGrid1.ColumnCount - 1 do
    begin
      if i = 0 then
        TMSFNCGrid1.Cells[j, i] := Format('Column %d', [j])
      else
        TMSFNCGrid1.Cells[j, i] := Format('(%d, %d)', [i, j]);
    end;
  end;
  TMSFNCGrid1.OnCellBeforeDraw := @TMSFNCGrid1CellBeforeDraw;
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  TMSFNCGrid1.Refresh;
end;

procedure TForm1.TMSFNCGrid1CellBeforeDraw(Sender: TObject; ACol, ARow: Integer; AGraphics: TTMSFNCGraphics; var ARect: TRectF; var ATextRect: TRectF;
  var ADrawText: Boolean; var ADrawBackGround: Boolean; var ADrawBorder: Boolean; var AllowDraw: Boolean);
begin
  if (SpinEdit1.Value > 0) and (SpinEdit1.Value < TMSFNCGrid1.RowCount) and (aRow = SpinEdit1.Value) then
  begin
    case aCol of
      0: AGraphics.Fill.Color := clYellow;
      1: AGraphics.Fill.Color := clRed;
      2: AGraphics.Fill.Color := clLime;
      3: AGraphics.Fill.Color := clAqua;
    end;
  end;
end;  

1 Like

Thank you, Pawel!

This is what I came up with, finally:

procedure TForm2.grdDataCellBeforeDraw(Sender: TObject; ACol, ARow: Integer; AGraphics: TTMSFNCGraphics;
  var ARect, ATextRect: TRectF; var ADrawText, ADrawBackGround, ADrawBorder, AllowDraw: Boolean);
begin
  if (ARow = grdData.FocusedCell.Row) and (ACol<>grdData.FocusedCell.Col) then
    AGraphics.Fill.Color := gcLightgray;
end;