Jeremy,
 
The following code colours any cell red with the word 'FIRE' in it and with blue text. I think this is what you want???
 
procedure TMainForm.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  Rect: TRect; State: TGridDrawState);
begin
  if StringGrid1.Cells[Col,Row] = 'FIRE' then
  begin
    StringGrid1.Canvas.Brush.Color := clRed;
    StringGrid1.Canvas.FillRect(Rect);
    StringGrid1.Canvas.Font.Color := clBlue;
    StringGrid1.Canvas.TextOut(Rect.Left, Rect.Top, StringGrid1.Cells[Col,Row])
  end;
end;
 
Regards,
Laurence Bevan
 
----- Original Message -----
Sent: Thursday, 17 February 2000 9:28 pm
Subject: RE: [DUG]: Multi coloured StringGrid rows --- a better description

No, the story is, that I am displaying some data I am capturing from an external device, in a string grid.
Some of the data, i.e. if the data contains the word FIRE or ALARM or the like, I want to paint the background of the row this appears in, in say RED.
Then if some other data comes in, I might want to paint THIS datas row insay GREEN or some colour anyway, but it could be 2 or 4 or 20 rows later.
I can do this BUT only if I specify the row....i.e. if row = 6 then canvas.brush.color:=clred etc.
BUT if I try to paint in normally, i.e. if Description = "FIRE" then canvas.brush.color:=clred etc. it will paint ALL the rows red not the one I WANT to be red.
I have tried in the onDrawCell event to do something silly like, if ARow = ARow then...do the color stuff, and also, if ARow = StringGrid1.RowCount-1 then do the colour stuff, but with no success.
Way I am trying figure out, and this is what I need some help on is, how to just paint hte ONE row a colour, and another row another colour, and not them all the same colour.
 
Is this a better description of what I am trying to do ??
 
Cheers, Jeremy Coulter
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Carl Reynolds
Sent: Thursday, February 17, 2000 5:32 PM
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Multi coloured StringGrid rows

I understand that you're trying to paint individual cells by position.  With DefaultDrawing = False, using the OnDrawCell event you'd do something like:
 
procedure TSurrealGridForm.sgSurrealDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  with Sender as TStringGrid, Canvas, Brush do begin
    case ARow * ACol mod 4 of
      3: Color := clWhite;
      2: Color := clBlue;
      1: Color := clRed;
      else Color := clGreen;
    end;
    FillRect(Rect);
  end;
end;
 
Does that help at all?  I only understood about half of your problem...  :)
 
Cheers,
Carl
 
-----Original Message-----
From: Jeremy Coulter [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 17 February 2000 14:42
To: Multiple recipients of list delphi
Subject: [DUG]: Multi coloured StringGrid rows

Hi all.
I have a string grid that I want to display diff. row colours in.
i.e. row 1 = red, row = blue, row 3= green etc.
 
I have been spending time figuring this ut, BUT the thing is, unless I specify a row, all the rows change colour.
This is a problem as I dont always know WHAT the coloumn number is, i.e. I cant add an item and then go, if ARow = Arow then blah as this didn't work either.
Can anyone help me out here ?
 
Jeremy Coulter (manager)
Visual Software Solutions

110 Harewood Road
Christchurch
ph +64 3 3521595
fx +64 3 3521596
cell +21 2533214
http://www.vss.co.nz
 

Reply via email to