Board index » delphi » Cell color in a stringgrid cell

Cell color in a stringgrid cell

I have a string grid and would like to be able to change the color of the
string in selected cells. Most of the text would be black but I would like
to change the text to red in certain cells at run time. Thanks
 

Re:Cell color in a stringgrid cell


Quote
"Lauren Johnson" wrote:
> I have a string grid and would like to be able to change the color
of the
> string in selected cells. Most of the text would be black but I
would like
> to change the text to red in certain cells at run time. Thanks

You can draw the text manually in the OnDrawCell event ie like this:

{--------------------}
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
Integer; Rect: TRect; State: TGridDrawState);
var
  S: string;
begin
  { if this cell should be red then }
  with Sender as TStringGrid do
  begin
    Canvas.FillRect(Rect);
    S := Cells[ACol, ARow];
    Canvas.Font.Color := clRed;
    DrawText(Canvas.Handle, PCHAR(S), Length(S), Rect, DT_TOP OR
DT_LEFT);
  end;
  { else, the default draw takes care of it }
end;
{--------------------}

HTH
-ThomasN

Re:Cell color in a stringgrid cell


or use a better stringgrid like TAlignStringGrid from
http://www.hoestemeiercom

Thomas Bauer

"Lauren Johnson" <ljohn...@inav.net> schrieb im Newsbeitrag
news:998rsg$e6m$1@news.inav.net...

Quote
> I have a string grid and would like to be able to change the color of the
> string in selected cells. Most of the text would be black but I would like
> to change the text to red in certain cells at run time. Thanks

Other Threads