Change Color in Grid

Hello,

it does not seem to go to change the color of the cell when you click into it. At least I can not find a solution that works.
My previous path which does not provide the desired result:

procedure TForm1.GridGetCellColor(Sender: TObject; ARow, ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
begin
  if ARow > 0 then
  begin
    if Grid.IsSelected(ACol,ARow) then
      ABrush.Color := clYellow
    else
      ABrush.Color := clWhite;
  end;
end;

Maybe someone knows a way

regards
Thoren

Hi Thoren,

did you try with CellChanging event?

It give you old and new cell coordinate.

The cell color, if this is the main matter, can be changed with the properry Colors[Col,Row]

You have to consider the selectioncolor property too; It gives the cel color who you are pointed. Also consider ActiveCellColor that give the cell color when you enter in edit mode.



With something like that you can change the color (sg1 : TAdvStringGrid)



procedure TFM.SG1CellChanging(Sender: TObject; OldRow, OldCol, NewRow,

NewCol: Integer; var Allow: Boolean);

begin

    if Newcol=2 then SG1.SelectionColor:=clSkyBlue

    Else

    SG1.SelectionColor:=clMaroon;

end;



Hope is you are loking for.



Regards

Daniele