Re: TZF - TzGrid Colors

Eitan Gilboa <[email protected]> Tue, 21 Oct 2003 16:49:58 +0200
Newsgroups gmane.comp.lang.delphi.topaz
Message-ID <[email protected]>
Try this:

Show a ROW of a DBGrid in a different color
We have another trick to show columns of a DBGrid in different color, in
short, the one:

[61] - Display a DBGrid column in a different color

In this other one, we will change the color of a whole line, that is to say,
of a whole register (a register or those that complete a certain condition).

The theme is to get that the comparison of if it is a record to show of
another color, be not carried out once for each field of each record, but
once for registration, winning this way in speed.
For it, we will calculate the color with which will paint the record just in
one of the columns of the DBGrid, using this color calculated in the rest of
the columns.
So that this serves?, for example, do imagine a list of clients shown in a
DBGrid... could we mark in red those clients that owe us money...

The example:

We will use the Animals.DBF table of the Delphi's demos:

# Put a Table and asociate it with Animals.DBF table of the Delphi's demos

# Put a Datasource link to the table

# Put a DBGrid (DBGrid1) link to DataSource

# Declare a TColor variable in the private of the form:


   private
     { Private declarations }
     UnColor:TColor;


# Put this code in the OnDrawColumnCell of the DBGrid1:

 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
   DataCol: Integer; Column: TColumn; State: TGridDrawState);
 begin
   {Si es la primera columna, calculamos el color}
   {UnColor debe estar declarada global a la form}

   {If it is the first column, we calculate the color}
   {UnColor should be declared as global to the form}
   if DataCol=0 then
     if Table1Size.AsInteger>10
       then UnColor:=clRed
       else UnColor:=clBlack;

   with (Sender As TDBGrid).Canvas do
   begin
     Font.Color:=UnColor;
     FillRect(Rect);
     TextOut(Rect.Left, Rect.Top, Column.Field.AsString);
   end;
 end;

A tip improvement:

 procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
   DataCol: Integer; Column: TColumn; State: TGridDrawState);
 begin
   {Si es la primera columna, calculamos el color}
   {UnColor debe estar declarada global a la form}

   {If it is the first column, we calculate the color}
   {UnColor should be declared as global to the form}
   if DataCol=TStringGrid(Sender).LeftCol-1 then
     if Table1Size.AsInteger>10
       then UnColor:=clRed
       else UnColor:=clBlack;

   with (Sender As TDBGrid).Canvas do
   begin
     Font.Color:=UnColor;
     FillRect(Rect);
     TextOut(Rect.Left, Rect.Top, Column.Field.AsString);
   end;
 end;

Best wishes,

Eitan.
URL: http://perso.wanadoo.fr/eitang

--^----------------------------------------------------------------
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
--^----------------------------------------------------------------