使用DBGrid的OnDrawColumCell时间,判断Fields[n].AsInteger,然后赋值了。
procedure TForm1.DBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if query1.FieldByName('Col1').AsString <> '' then
dbgrid1.Canvas.Brush.Color := $00E0FFFF
else
dbgrid1.Canvas.Brush.Color := clWhite;
if (gdSelected in State) then
begin
dbgrid1.Canvas.Brush.Color := clNavy;
dbgrid1.Canvas.Font.Color := clWhite;
end;
dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;