把defaultdrawing设置为false
然后相应onDrawDataCell事件。。我自己写过一个例子
如下
表中有一个名字为bz的boolean类型字段,我在dbgrid中自己建立了一个名字为abc的列
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
OLDCLO: TCOLOR;
begin
dbgrid1.Canvas.Font.Color := $00000000;
if field.FieldName = 'abc' then //判断是否正在重绘abc字段
begin
dbgrid1.Canvas.Brush.Color := $00FFFFFF;
dbgrid1.Canvas.FillRect(rect);
oldclo := dbgrid1.Canvas.Pen.Color;
dbgrid1.Canvas.Pen.Color := $00FF0000;
if table1.FieldByName('BZ').AsBoolean = True then
begin //如果正在重绘abc并且bz=true 则在abc的位置画圆
DBGRID1.Canvas.Arc(rect.Left, rect.Top, rect.Right, rect.Bottom, rect.Left, rect.Top, rect.Left, rect.Top);
end
else
begin //abc的位置画叉
dbgrid1.Canvas.MoveTo(rect.Left, rect.Top);
dbgrid1.Canvas.LineTo(rect.Right, rect.Bottom);
dbgrid1.Canvas.MoveTo(rect.Left, rect.Bottom);
dbgrid1.Canvas.LineTo(rect.Right, rect.top);
end;
dbgrid1.Canvas.Pen.Color := oldclo;
end
else
begin //在重绘别的字段的时候 用颜色区分 bz的属性
if table1.FieldByName('BZ').AsBoolean = True then
begin
dbgrid1.Canvas.Brush.Color := $00A6E7F7;
end
else
begin
dbgrid1.Canvas.Brush.Color := $00B8BCE4;
end;
dbgrid1.DefaultDrawDataCell(rect, field, state); //在调用dbgrid的DefaultDrawDataCell过程重绘除abc以外的所有字段
end;
end;