根据不同的字段值,在DBGrid1表格中不同行间显示红,蓝,绿三种颜色,可以在DBGrid1的OnDrawDataCell事件中加入这段代码:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Query1.FieldByName('Red').AsString = 'A' then //这是判断条件,显示红色
DBGrid1.Canvas.Font.Color := clRed;
if Query1.FieldByName('Blue').AsString = 'B' then //这是判断条件,显示蓝色
DBGrid1.Canvas.Font.Color := clBlue;
if Query1.FieldByName('Green').AsString = 'C' then //这是判断条件,显示绿色
DBGrid1.Canvas.Font.Color := clGreen;
......
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); //最重要的是这一行代码[/b]
end;