Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TDBGrid - color scheme

Status
Not open for further replies.

guava65

Programmer
Jul 20, 2001
238
US
I'd like to show a TDBGrid with different color rows. The color of the row would be mased on the value of a field in the dataset. If this is not possible, I'd like to try the same effect with the font color.

Any ideas?

thanks in advance,
cg Mahalo,
cg
 
Are you looking for a tool that will allow you to do this or a way to do it on your own?

If you make your own you could override the DrawCell procedure and add
Canvas.Brush.Color :=clGreen;
Canvas.FillRect(ARect);


before the inherited paint call, and that might work. I've done that sort of thing with grids, but not with a data aware grid.
TealWren
 
Apparently there is a way to achieve this with "OnDrawColumnCell" but I don't know how to put the code together to make it work.

Any help on using this feature to set a font color?

I tried:
------------------------------------------------------------
if table1.FieldByName('TrueFalse').AsBoolean = True then
DBGrid1.Canvas.Font.Color := clRed;
------------------------------------------------------------
I know I missed something but have no idea what it is.

Thanks in advance,
cg

Mahalo,
cg
 
TealWren is on the right track... Try this in the OnDrawDataCell event:

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin

with DBGrid1.Canvas do
begin
FillRect(Rect);

if (Field.FieldName = 'TrueFalse') and (Field.AsBoolean = True) then
Font.Color := clRed
else
Font.Color := clBlack;



TextRect(Rect, Rect.Left +1,Rect.Top +1, Field.AsString);
end;

end;

Andreas Nordlund
Software developer
 
Of course you can use

Brush.Color := clRed;
FillRect(Rect);
Font.Color := clBlue;
Font.Style := [fsBold];
TextRect(Rect, Rect.Left +1,Rect.Top +1, Field.AsString);


Then you can start building a very advanced Colorscheme.
Andreas Nordlund
Software developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top