Board index » delphi » dbgrid rows colored in interlaced two colors

dbgrid rows colored in interlaced two colors

How to color dbgrid rows just in two interlaced colors - Grey and Aqua e.g.
Rows in the grid are grouped by some field value. As a result I want to see
like:
3 rows in grey, next 4 rows in aqua , next 2 - in grey, next 5 - in aqua and
so on.

Any ideas, please.

Vlad Gonchar

 

Re:dbgrid rows colored in interlaced two colors


On Sun, 23 Sep 2001 00:02:32 -0700, "Vlad Gonchar" <vgonc...@ica.net>
wrote:

Quote
>How to color dbgrid rows just in two interlaced colors - Grey and Aqua e.g.
>Rows in the grid are grouped by some field value. As a result I want to see
>like:
>3 rows in grey, next 4 rows in aqua , next 2 - in grey, next 5 - in aqua and
>so on.

Painting is done in the DrawColumnCell event, with
DefaultDrawColumnCell, but you can make the brush (and/or the font)
suit your tastes beforehand, as in:

Procedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect:
TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
Begin
        If Table1.FieldByName('SomeField').AsInteger > 1234 then
                        DBGrid1.Canvas.Brush.Color:= clAqua
        else
                        DBGrid1.Canvas.Brush.Color:= clGrey;

        DefaultDrawColumnCell(Rect, DataCol, Column, State);
End;

Manuel Algora
m...@encomix.es

Re:dbgrid rows colored in interlaced two colors


Probely I was not clear enough in my explenation.

So, I am trying again.
How to color dbgrid rows just in two interlaced colors - Grey and Aqua e.g.
Rows in the grid are grouped by some field value by several in each group -
3 rows in first
group, 4 rows - in second group and so on. But color does not depent on that
value!
Current color depens on what color was before. Now it should be different.
I have to have only two colors, but grouping values - many. When retreiving
row
from db I am able to track the interlacing.

The problem is how works DrawColumnCell when I scroll back through already
colored
groups. It looks like it will smash older colors.

Vlad Gonchar

Other Threads