以下是我的Unit中的代码:
[code]
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADOColorDBGrid, DBGridEh, Grids, DBGrids, DB, ADODB;type
TMyDBGrid = class(TDBGrid)
procedure KeyDown(var Key: Word;
Shift: TShiftState); override;
end; TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyDBGrid1: TMyDBGrid;implementation{$R *.dfm}procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
begin
Key := 0;
PostMessage(DBGrid1.Handle, WM_KEYDOWN, VK_TAB, 0);
end
else
inherited;
end;{ TMyDBGrid }procedure TMyDBGrid.KeyDown(var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
begin
Key := 0;
PostMessage(Handle, WM_KEYDOWN, VK_TAB, 0);
end
else
inherited;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MyDBGrid1 := TMyDBGrid.Create(Self);
with MyDBGrid1 do
begin
Parent := Self;
DataSource := DataSource1;
Align := alClient;
Options := DBGrid1.Options; ///////
Show;
end;
end;end.
[/code]DBGrid1的OnKeyDown事件正常响应;如果把DBGrid1的Options->dgAlwaysShowEditor设为True,MyDBGrid1的KeyDown就不响应了,反之则正常响应。为什么会这样???不解[:(][:(]
[code]
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ADOColorDBGrid, DBGridEh, Grids, DBGrids, DB, ADODB;type
TMyDBGrid = class(TDBGrid)
procedure KeyDown(var Key: Word;
Shift: TShiftState); override;
end; TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyDBGrid1: TMyDBGrid;implementation{$R *.dfm}procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
begin
Key := 0;
PostMessage(DBGrid1.Handle, WM_KEYDOWN, VK_TAB, 0);
end
else
inherited;
end;{ TMyDBGrid }procedure TMyDBGrid.KeyDown(var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
begin
Key := 0;
PostMessage(Handle, WM_KEYDOWN, VK_TAB, 0);
end
else
inherited;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MyDBGrid1 := TMyDBGrid.Create(Self);
with MyDBGrid1 do
begin
Parent := Self;
DataSource := DataSource1;
Align := alClient;
Options := DBGrid1.Options; ///////
Show;
end;
end;end.
[/code]DBGrid1的OnKeyDown事件正常响应;如果把DBGrid1的Options->dgAlwaysShowEditor设为True,MyDBGrid1的KeyDown就不响应了,反之则正常响应。为什么会这样???不解[:(][:(]
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货