0

I would like to have: if a boolean variable will set to true, should a cell (error message) in StringGrid be red. It isn't works automatically with OnDrawCell. How can I achieve it? Thanks in advance.

genakust
  • 89
  • 9

1 Answers1

3

In the OnDrawCell event, check the state of the boolean variable and if the correct cell is about to be drawn, set the colour to red.

See delphi : how can I change color of a cell in string grid.

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;  Rect: TRect; State: TGridDrawState);
begin
  if (myBooleanState) and (ACol = 3) and (ARow = 2) then
    with TStringGrid(Sender) do
    begin
      //paint the background red
      Canvas.Brush.Color := clRed;
      Canvas.FillRect(Rect);
      Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol, ARow]);
    end;
end;

When the state of the boolean is changed, just call MyStringGrid.Repaint or MyStringGrid.Invalidate.

Community
  • 1
  • 1
LU RD
  • 34,438
  • 5
  • 88
  • 296