2

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

RBA
  • 12,337
  • 16
  • 79
  • 126
Jessie M
  • 498
  • 1
  • 9
  • 23
  • 1
    I cannot really understand this question. Are you asking how the control fires the event? If so, it's just as easy for you as it is for us to look at the source code. – David Heffernan Feb 25 '13 at 10:21
  • now it should be more clear :) – RBA Feb 25 '13 at 10:28
  • 1
    @RBA - It sure is more clear. But is it really the question OP meant to ask? – Sertac Akyuz Feb 25 '13 at 10:30
  • I'm almost sure that this is what OP asks, because DBGrid does not have an OnColResize or some similar event. If the OP does not provide more details we can only assume that this is what he wants. OP can also modify the question if the actual edit is not what he wants. – RBA Feb 25 '13 at 10:32
  • @SertacAkyuz - it seems that is related also to this question http://stackoverflow.com/questions/15020306/how-to-adjust-dbgrid-columns-width-automatically – RBA Feb 25 '13 at 10:38

2 Answers2

3

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;
bummi
  • 27,123
  • 14
  • 62
  • 101
3

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.

RBA
  • 12,337
  • 16
  • 79
  • 126