Home » Delphi » Delphi DBGrid 改变行颜色

DBGrid->事件->OnDrawColumnCell

procedure TForm1.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
    if gdSelected in State  then //改变选中行的颜色
      begin
       DBGrid2.Canvas.Brush.Color :=clActiveBorder;
       DBGrid2.Canvas.Font.Color :=clBlack;
       Canvas.FillRect(Rect);
      DBGrid2.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end
      else
      begin
        //改变特定行颜色
        if adoquery3.FieldByName('状态标志').AsString='8' then
        begin
           DBGrid2.Canvas.Font.Color :=clBlue;
           DBGrid2.DefaultDrawColumnCell(Rect,DataCol,Column,State);
        end
       else
        begin //默认行颜色
           DBGrid2.Canvas.Font.Color :=clGreen;
           DBGrid2.DefaultDrawColumnCell(Rect,DataCol,Column,State);
        end;
      end;
end;

标签: Delphi DBGrid 改变行颜色

添加新评论

V