关于dbgrid和dbgrideh的字段宽度问题 ( 积分: 10 )

  • 主题发起人 主题发起人 hoyaxun
  • 开始时间 开始时间
H

hoyaxun

Unregistered / Unconfirmed
GUEST, unregistred user!
在dbgird 中有时候它的宽度不够,字段显示不下,我们会用鼠标来拖动,我想捕获这个宽度改变的事件应该怎么做啊?
 
在dbgird 中有时候它的宽度不够,字段显示不下,我们会用鼠标来拖动,我想捕获这个宽度改变的事件应该怎么做啊?
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, Buttons, DB, ADODB;
type
TNDBGrid = Class(TDBGrid)
protected
procedure ColWidthsChanged; override;
//procedure AdjustSize(Index, Amount: Longint; Rows: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;

type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
procedure DBGrid1ColumnMoved(Sender: TObject; FromIndex,
ToIndex: Integer);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DBGrid1ColumnMoved(Sender: TObject; FromIndex,
ToIndex: Integer);
begin
ShowMessage('Moved!')
end;

{ NDBGrid }

procedure TNDBGrid.ColWidthsChanged;
var
Column: TColumn;
begin
inherited;
Column := Self.Columns[self.SelectedIndex];
if Column <> nil then
ShowMessage(Column.Title.Caption);
end;


constructor TNDBGrid.Create(AOwner: TComponent);
begin
inherited;
end;

destructor TNDBGrid.Destroy;
begin
inherited;
end;


procedure TForm1.BitBtn1Click(Sender: TObject);
var
AGrid: TNDBGrid;
column: TColumn;
begin
AGrid := TNDBGrid.Create(Self);
AGrid.DataSource := DataSource1;
AGrid.Parent := Self;

{column := AGrid.Columns.Add;
column.Title.Caption := 'test';
column := AGrid.Columns.Add;
column.Title.Caption := 'move';
column := AGrid.Columns.Add;
column.Title.Caption := 'width';
}
end;


end.
 
接受答案了.
 
后退
顶部