根据条件,DBGrid不同行显示不同的颜色

procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.Open;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Table1.Close;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DBGrid1.DataSource.DataSet.RecNo mod 2 = 0 then //条件判断
begin
with DBGrid1 do
begin
Canvas.Font.Color:=clRed;
Canvas.Brush.Color:=clYellow;
end;
end;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end; 
 

你可能感兴趣的:(DELPHI-数据库)