响应OnDrawColumnCell事件,例如下面代码摘自我过去开发的代码,供参考。 procedure TSelectForm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var Value: String; with (Sender as TDBGrid),(Sender as TDBGrid).Canvas do begin if not (gdSelected in State) then case StrToInt((DataSource.DataSet)['dydj']) of 220: Font.Color := clRed; 110: Font.Color := clNavy; 35: Font.Color := clMaroon; 10: Font.Color := clBlack; else Font.Color := clBlack; end else begin Font.Color := clWhite; Brush.Color := clBlack; end; FillRect(Rect); Value := ''; if Assigned(Column.Field) then Value := Column.Field.DisplayText; TextOut(Rect.Left+3, Rect.Top+1, Value); end;
procedure TSelectForm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Value: String;
with (Sender as TDBGrid),(Sender as TDBGrid).Canvas do
begin
if not (gdSelected in State) then
case StrToInt((DataSource.DataSet)['dydj']) of
220: Font.Color := clRed;
110: Font.Color := clNavy;
35: Font.Color := clMaroon;
10: Font.Color := clBlack;
else
Font.Color := clBlack;
end
else
begin
Font.Color := clWhite;
Brush.Color := clBlack;
end;
FillRect(Rect);
Value := '';
if Assigned(Column.Field) then
Value := Column.Field.DisplayText;
TextOut(Rect.Left+3, Rect.Top+1, Value);
end;