Thanks to everyone's help.  Here is what I got to work:

1.  I left the DefaultDrawing property of the stringGrid set to True.
If I turned it off, I lost the color and shape of the fixed rows.

2.  I added the Specific StringGrid name to the canvas property and only
modified the cells that I needed to.  I left the Fixed cells untouched.

Here is my code:

procedure TForm1.XStrGrDailyDrawCell(Sender: TObject; ACol, ARow:
Integer;
  Rect: TRect; State: TGridDrawState);
Var
 OldColor : TColor;
 OldBrush : TBrush;

begin
  with XStrGrDaily.canvas do
  begin
  OldColor := Font.Color;
  OldBrush := Brush;
  brush.Style := bssolid;
   If (ACol >= 1) and (ARow >= 1) then
    If ApptArray[ARow] = False
   then
    Begin
    Brush.Color := clwindow;
    XStrGrDaily.canvas.Font.Style := [];
    end
  else
   Begin
    Brush.Color := clAqua;
    Font.color := clBlack;
    XStrGrDaily.canvas.Font.Style := [fsBold];  
   end;
   FillRect(Rect);
   SetBkMode(Canvas.Handle,Transparent);
  TextOut(Rect.left+2,Rect.Top+2,XStrGrDaily.Cells[acol,arow]);  //paint
cell
  Font.color := OldColor;
  brush := OldBrush;
  end;
end;

*************************************
I am not sure if I need to restore the original Font.color and brush but
maybe it is needed when I am handling the fixed cells.

Anyway, it works and I am thrilled with the results.  Thanks again for
your help!

Tom Nesler

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of ianhinson
Sent: Wednesday, April 25, 2007 1:23 AM
To: [email protected]
Subject: [delphi-en] Re: Setting background color of String grid row


Based on the code you supplied you're using the wrong Canvas.

Inside you hander you have
> begin
>   with canvas do
That refers to the form's canvas, not the StringGrid's canvas.

You should use:
with (Sender as TStringGrid).Canvas do

Also, address your other references to "canvas" that appear in 
several lines below that, for the same reason.

Ian.

--- In [email protected], "Nesler, Thomas J" <[EMAIL PROTECTED]> 
wrote:
>
> Hello!
>  
> I am trying to highlight certain rows of a string grid based on
> different criteria.  Whenever I work with the Win32 interface, I 
always
> get confused as to what is going on and what I should do.  I 
realize I
> need to use the OnDrawCell event to take over the painting of the 
cell,
> but I can't seem to get the procedure to leave in the default 
attributes
> when I don't want to override the standard colors.  
>  
>  
> Another point of confusion:  If I Say Default drawing = false, does 
that
> mean I can turn on Default drawing after I am finished doing my 
custom
> work?
>  
> All  the examples I have seen so far, are very poorly documented 
(IMO)
> so they don't explain what is going on at all.  Does anyone have a
> sample of code to do this?
>  
> Here is my routine:
>  
> procedure TForm1.XStrGrDailyDrawCell(Sender: TObject; ACol, ARow:
> Integer;
>   Rect: TRect; State: TGridDrawState);
> Var
>  OldColor : TColor;
>  OldBrush : TBrush;
>  
> begin
>   with canvas do
>   begin
>   OldColor := Font.Color;  //Save default Font color
>   OldBrush := Brush;       //Save default Brush 
>   brush.Style := bssolid;
>    If ((ACol < XStrGrDaily.Fixedcols) OR (ARow < 
XStrGrDaily.FixedRows))
> then  //Ignore fixed rows
>    If ApptArray[ARow] = False  //Array that turns on color when 
true or
> turns off color when false
>    then
>     Begin
>     Brush.Color := clwindow;
>     canvas.Font.Style := [];
>     end
>   else
>    Begin
>     Brush.Color := clBlue;
>     canvas.Font.Style := [fsbold];
>    end;
>  
>    FillRect(Rect);
>    SetBkMode(Canvas.Handle,Transparent);
>  
>   TextOut(Rect.left+2,Rect.Top+2,XStrGrDaily.Cells
[acol,arow]);  //paint
> Cell
>   Font.color := OldColor;
>   brush := OldBrush;
>  
>   end;
> end;
> 
> Thanks!
>  
> Tom Nesler
>  
> 
> 
> [Non-text portions of this message have been removed]
>




-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links



Reply via email to