写DrawColumnCell事件即可
只是需要在数据集中表明哪些记录是什么颜色的记录 这样画的时候才能处理
procedure ReBrushDBGridEh(Rect:TRect;Grid:TDBGridEH;Column:TColumnEH;
State:TGridDrawState;cColor:TColor;bFont:boolean=true);
var
B:TRect;
iLeft:integer;
sDisplayText : string;
begin
if gdSelected in State then
Exit;
if Column = nil then
sDisplayText := ''
else
if Column.Field = nil then
sDisplayText := ''
else
sDisplayText := Column.Field.DisplayText;
B:=Rect;
Grid.Canvas.Brush.Color := cColor;
case Column.Alignment of
taLeftJustify:
iLeft := B.Left + 2;
taRightJustify:
iLeft := B.Right - Grid.Canvas.TextWidth(sDisplayText) - 3;
else
iLeft := B.Left + (B.Right - B.Left) shr 1
- (Grid.Canvas.TextWidth(sDisplayText) shr 1);
end;
if bFont then
Grid.Canvas.Font.Color := clBlack;
Grid.Canvas.TextRect(B, iLeft, B.Top + 2, sDisplayText);
end;
procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
begin
if CDS_CheckPK.FieldByName('ZC_QUAN_GD').AsFloat>0 then
ReBrushDBGridEh(Rect,DBGridEh_PK,Column,State,$00F7F1F0);
end;