看这里:
在DBGrid的OnDrawDataCell事件里可以改变单元格的颜色
某一列的颜色可直接改
procedure TForm1.Button1Click(Sender: TObject);
begin
query1.close;
query1.sql.text:='select * from animals';
query1.open;
end;
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
DBGrid1.Canvas.Font.Color:=clred;
DBGrid1.Canvas.Brush.Color:=clgray;
{//改变某个单元格的颜色
if (Field.FullName='SIZE')and (Field.AsInteger=2) then
begin
DBGrid1.Canvas.TextRect(rect,rect.Left,rect.Top,Field.AsString);
end;}
//改变某行的颜色,该行的NAME字段值=aaa
if Field.DataSet.FieldByName('NAME').asString='aaa' then
DBGrid1.Canvas.TextRect(Rect,rect.Left,rect.Top,Field.AsString);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//改变某个列的颜色
DBGrid1.Columns[1].Color:=clgreen;
DBGrid1.Columns[1].Font.color:=clred;
end;
good luck!