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.
Asked
Active
Viewed 1,345 times
1 Answers
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
.