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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGRID and Colors

Status
Not open for further replies.

Regany

Programmer
Aug 27, 2004
72
LV
How to make severally field fonts in DBGrid to be in different color (for example if value is more than 10 then its green)? But it must be called from ButtonClick not from DrawColumnCell!

I know "DBGrid1.Columns[1].Font.Color:=clgreen;" but thats for whole column! :(


I hope my question is understandable!
 
use the DrawColumnCell to draw on the Grids Canvas, there you can place the if like so:

Code:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin

 // pseudo code
  if Value > 10 then
  DBGrid1.Columns[1].Font.Color:=clgreen;

  DBGrid1.Canvas.TextOut(Rect.Left,Rect.Top,'text from dbfield');

end;

hth
- fruNNik
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top