我有一段代碼是這樣寫的,你參照一下吧
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var oldcolor:Tcolor;
oldpm:Tpenmode;
begin
if (sender as Tdbgrid).DataSource.DataSet.fieldbyname('conspc').AsInteger<>0 then
with (sender as Tdbgrid).Canvas do
begin
pen.Mode:=pmmask;
font.Color:=clblue;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;
with mygrd(sender) do begin
if datalink.ActiveRecord=row-1 then
canvas.Brush.Color:=cllime;
//else
//canvas.Brush.Color:=clred;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;
end;