M
maple_guo
Unregistered / Unconfirmed
GUEST, unregistred user!
我从TDBGrid继承了一个MyDBGrid,并改写了一下KeyDown事件,然而当我把dgAlwaysShowEditor改为True时,KeyDown事件就不响应了,请帮忙看一下。(50分)<br />以下是我的Unit中的代码:
DBGrid1的OnKeyDown事件正常响应;
如果把DBGrid1的Options->dgAlwaysShowEditor设为True,MyDBGrid1的KeyDown就不响应了,反之则正常响应。为什么会这样???不解[][]
代码:
unit Unit1;
interface
uses
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.
DBGrid1的OnKeyDown事件正常响应;
如果把DBGrid1的Options->dgAlwaysShowEditor设为True,MyDBGrid1的KeyDown就不响应了,反之则正常响应。为什么会这样???不解[][]