DBGrid - problem with DrawColumnCell lazarus / 39-Graphics ---------------------------------------------------------------------- tanguy · 2013-07-29 07:43 Hello, My goal is to color a cell in a DBGrid The color is depending of value  of field in the same column i use ondrawcolumncell  :      if Column.FieldName='TEST1' then      begin           val_test:= column.Field.AsInteger;           case val_test of                -1 : Column.Color:= clGray;                0 : Column.Color:= clGreen;                1 : Column.Color:= clYellow;                2 : Column.Color:= clRed;           end;      end; but i don't have the good result lines  Value of column  - Color of column    0      : Green    2      : Green   -1      :  Red   -1      : Gray   -1      : Gray    2      : Gray    2      : Red    1     :  Red    0     : Yellow .... I think i don't use the good method ... if you have any idea Many thanks ---------------------------------------------------------------------- howardpc · 2013-07-29 10:41 You need to use the OnPrepareCanvas event, and not try to repeatedly change the Color of the entire column, just the individual cell. Something like this: Code: [Select]procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;   Column: TColumn; AState: TGridDrawState); const ColumnToColour = 1; //change this to appropriate value begin   if DataCol = ColumnToColour   then begin     case Column.Field.AsInteger of      1: DBGrid1.Canvas.Brush.Color := clBlue;      2: DBGrid1.Canvas.Brush.Color := clRed;      3: DBGrid1.Canvas.Brush.Color := clGreen;      // 4: ... etc.     end;   end; end; ---------------------------------------------------------------------- tanguy · 2013-07-29 11:59 Many thanks it's working nice