我有一个TDBGrid组件。我需要在调整网格的列大小时捕获触发的事件。

最佳答案

获得事件的唯一地方似乎是重写ColWidthChanged ...

type
  TDBgrid=Class(DBGrids.TDBGrid)
       private
       FColResize:TNotifyEvent;
       procedure ColWidthsChanged; override;
       protected
       Property OnColResize:TNotifyEvent read FColResize Write FColResize;
  End;

  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    DBGrid1: TDBGrid;
    ADODataSet1: TADODataSet;
    DataSource1: TDataSource;
    procedure FormCreate(Sender: TObject);
  private
    procedure ColResize(Sender: TObject);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TDBgrid }

procedure TDBgrid.ColWidthsChanged;
begin
  inherited;
  if Assigned(FColResize) then  FColResize(self);

end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  DBgrid1.OnColResize := ColResize;
end;

procedure TForm1.ColResize(Sender:TObject);
begin
  Caption := FormatDateTime('nn:zzz',now)  ;
end;

10-07 23:57