I use the following custom OnDraw to colorize background of a cell depending on column number:
procedure TForm_ControlPanel.aoc_gridDrawCell(Sender: TObject;
ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
grid: TStringGrid;
S: string;
SavedAlign: word;
begin
grid := Sender as TStringGrid;
if (ACol = 2) and (ARow >= 1) then
begin
S := grid.Cells[ACol, ARow]; // cell contents
grid.Canvas.Brush.Color := clGreen;
grid.Canvas.FillRect(Rect);
SavedAlign := SetTextAlign(grid.Canvas.handle, TA_CENTER);
grid.Canvas.TextRect(Rect, Rect.Left + (Rect.Right - Rect.Left) div 2,
Rect.Top + 5, S);
SetTextAlign(grid.Canvas.handle, SavedAlign);
grid.Canvas.Brush := grid.Brush;
end;
end;
but in the result i always have a "bar" on the left side which is not colored:
I am using Delphi XE6.