Afternoon all,
I'm trying to work out if it is possible to directly call the onDrawCell procedure to force a String Grid to redraw itself so that cells in a column can be coloured according to if they match values in a string list, the code is below and hopefully will make more sense!
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState);
var
StringComp: LongInt;
rc: Integer;
begin
rc:= ReturnList.Count;
I:= 1;
if rc < 1 then
While i < StringGrid1.RowCount do
begin
if i > rc then exit;
StringComp:=AnsiCompareStr(ReturnList.Strings[i],StringGrid1.Cells[3, i]);
if StringComp = 0 then
begin
StringGrid1.Canvas.Brush.Color:=clGreen;
StringGrid1.Canvas.FillRect(aRect);
StringGrid1.Canvas.TextRect(aRect, aRect.Left, aRect.Top, StringGrid1.Cells[3, i]);
i:= i + 1;
if gdFocused in aState then
StringGrid1.Canvas.DrawFocusRect(aRect);
end
else
begin
StringGrid1.Canvas.Brush.Color:=clRed;
StringGrid1.Canvas.FillRect(aRect);
StringGrid1.Canvas.TextRect(aRect, aRect.Left, aRect.Top, StringGrid1.Cells[3, i]);
i:= i + 1;
if gdFocused in aState then
StringGrid1.Canvas.DrawFocusRect(aRect);
end;
end;
end;
NOTE
The variable i is declared as a public variable and is used a generic counter for loops.