Re: TZF - TzGrid Colors

Marie Vihonsky <[email protected]> Tue, 04 Nov 2003 09:28:48 -0500
Newsgroups gmane.comp.lang.delphi.topaz
Message-ID <[email protected]>
Hi Bob,

I think the 'Table1size' variable refers to a 'Field' in the grid.  So 
you need to substitute a valid field reference from your database.

Here's some alternate code for changing colors:
-----------------------------------------------------
Change Color of Grid Cell

procedure TCountForm1.TzGrid1DrawDataCell(Sender: TObject;
   const Rect: TRect; Field: TField; State: TGridDrawState);
var  s : array[0..255] of char;
      FieldAsString : string;
begin
    with (sender as TTzGrid).canvas do begin
       FieldAsString := Field.AsString;
       if GetDBaseType(Field) in ['N'] then   {a number}
            Brush.Color := clAqua;
       FillRect(Rect);
       ExtTextOut(Handle, Rect.Left + 2,Rect.Top + 2,
          ETO_OPAQUE or ETO_CLIPPED, @Rect,
          StrPCopy(S, FieldAsString), Length(FieldAsString), nil);
    end;
end;
--------------------------------------------
Display a DBGrid column in a different color

# First, put the DefaultDrawing property of the DBGrid to False
# Later, put this code into OnDrawDataCell event of the DBGrid:

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
              Field: TField; State: TGridDrawState);
begin
    { NOMBRE this the field name to paint in a diferent color }
    if Field.FieldName = 'NOMBRE' then
       (Sender as TDBGrid).Canvas.Font.Color := clRed;
       (Sender as TDBGrid).Canvas.TextRect(Rect, Rect.Left + 2,
                  Rect.Top + 2, Field.AsString);
end;
------------------------------------------------------------
Alternating colors in a grid

procedure TForm1.TzGrid1ChangeColorsEvent(Sender: TObject; curRow: Integer;
   var IndicatorColor, CellColor, CellTextColor, HiliteColor,
   HiliteTextColor, DeletedColor, DeletedTextColor: TColor);
begin

    With (sender as TTzGrid) do begin
      if (CurRow MOD 2)=0 then begin
          CellColor:=$00B3F8FF;
          HiliteColor:=$00B3F8FF;
          CellTextColor:=clBlack;
          HiliteTextColor:=clBlack;
          end
      else begin
        CellColor:=$00E1E1C6;
        HiliteColor:=$00E1E1C6;
        CellTextColor:=clBlack;
         HiliteTextColor:=clBlack;
        end;
    end;
    if TzDbf1.Deleted then begin
      if (curRow MOD 2)=0 then begin
         DeletedColor:=$00B3F8FF;
         HiliteColor:=$00B3F8FF;
         CellTextColor:=clBlack;
          HiliteTextColor:=clBlack;
         end
      else begin
         DeletedColor:=$00E1E1C6;
         HiliteColor:=$00E1E1C6;
         CellTextColor:=clBlack;
          HiliteTextColor:=clBlack;
         end;
    end;
end;
----------------------------------------------------

Maybe one of these, or a combination, will get you what you want.

Marie

--^----------------------------------------------------------------
This email was sent to: [email protected]

EASY UNSUBSCRIBE click here: http://topica.com/u/?clvXPN.a5kvff.Z2NsZHQt
Or send an email to: [email protected]

TOPICA - Start your own email discussion group. FREE!
http://www.topica.com/partner/tag02/create/index2.html
--^----------------------------------------------------------------