Andromeda
Andromeda

Reputation: 550

Where the TDBGrid Columns resize event was triggered

I have a TDBGrid component. I need to catch the event triggered when I'm resizing a column of the grid.

Upvotes: 2

Views: 4107

Answers (2)

RBA
RBA

Reputation: 12584

you need to create a descendent of TDBGrid and implement the event by yourself. Something like this:

unit MyDBGrid;

interface

type
  TMyDBGrid = class(TDBGrid)
  private
    FOnColResize: TNotifyEvent;
  protected
    procedure ColWidthsChanged; override;
  public
  published
    property OnColResize: TNotifyEvent read FOnColResize write FOnColResize;
  end;

implementation

{ TMyDBGrid }

procedure TMyDBGrid.ColWidthsChanged;
begin
  inherited;
  if (Datalink.Active or (Columns.State = csCustomized)) and
    AcquireLayoutLock and Assigned(FOnColResize) then
    FOnColResize(Self);
end;

end.

this should work, I don't have time now to test it.

Upvotes: 3

bummi
bummi

Reputation: 27377

the only place to get an events seems to be overriding 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;

Upvotes: 3

Related Questions