I have a column which have only "yes" and "no" values. I want if column value is "yes" then only that cell background color is red else "no" then background color is yellow but this code colors whole row :
if ADOTable1.FieldByName('Clubs').AsString = 'yes' then
begin
DBGrid1.Canvas.Brush.Color := clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
EDIT
Thanks for your replies. My real code look like that. The "netice" column only have "L, D, W,".
if Column.FieldName = 'netice' then
begin
if ADOTable1.FieldByName('netice').AsString = 'L' then
DBGrid1.Canvas.Brush.Color := clgreen ;
if ADOTable1.FieldByName('netice').AsString = 'D' then
DBGrid1.Canvas.Brush.Color := clRed ;
if ADOTable1.FieldByName('netice').AsString = 'W' then
DBGrid1.Canvas.Brush.Color := clYellow ;
end;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
but I need L--green, D--red, W--yellow I am using Delphi 2010.
var ADS:TDataset; begin Ads := TDBGrid(Sender).DataSource.DataSet; if Column.FieldName = 'netice' then begin if Ads.FieldByName('netice').AsString = 'L' then DBGrid1.Canvas.Brush.Color := clgreen ; .........
– BuckishColumn.Field
gives you the exact linked dataset field. Hence I've used it in my code below. But here I'm not feeling much safe from thatFieldName
comparison (the OP used first capital in the first case, not in the latter). Maybe somethinglike this
might work. – Glower