The error is "Cell does not contain integer value".
The cells having values are integer, some cells are empty with no value.
This code should work?
procedure TfrmMyForm.GridGetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
begin
// Not if fixed row
if ARow>0 then
begin
// Not if empty
if grid.cells[ARow,5]<>'' then
// If value>0
if Grid.Ints[ARow,5]>0 then
ABrush.Color:=clred;
end;
end;
I can only suspect that OnGetCellColor is triggered for a cell not empty and not containing a number. I suggest to check the values returned by grid.Cells[].
You could also change this code to:
if TryStrToInt(grid.Cells[arow,5]) > 0 then ...
Positive values in col 1 should have a black font color, negative values should have a red font color.
procedure TForm1.GridGetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
begin
if ACol=1 then
if Grid.Ints[ARow,1]<0 then
AFont.Color:=clred
else
AFont.Color:=clblack;
end;
Sample project with empty grid just to test above code. But values that are less than 0 does not have a red font color, the font color is still black even if I enter the value of -2 or other negative values.
Is GridGetCellColor the correct event to give negative values a red font color in a stringgrid? If not, what event should I use?
I have used 7-8 hours trying to get it work, without any success Sample code woud be great