处理DBGrid的OnDrawColumnCell事件:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.ID = 0 then
if Column.Field.AsInteger < 0 then
DBGrid1.Canvas.FillRect(Rect); //仅填充当前格,不写任何文字;
if Column.ID = 1 then
begin
DBGrid1.Canvas.FillRect(Rect); //填充背景
if Column.Field.AsBoolean then
DBGrid1.Canvas.TextRect(Rect, 2, 2, '是') //可以做一下其它处理,比如居中
else
DBGrid1.Canvas.TextRect(Rect, 2, 2, '否');
end;
end;