Board index » delphi » Delete a record in a TDBGrid with the Delete Key (and not Ctrl-Delete)

Delete a record in a TDBGrid with the Delete Key (and not Ctrl-Delete)

Hi!
I have this problem:
I want to delete a record in a TDBGrid simply by pressing the Delete key,
and not the Ctrl-Delete.
I tried to override the OnkeyPress event, without result.
Any suggestion?

Thanks in advance

Andrea

 

Re:Delete a record in a TDBGrid with the Delete Key (and not Ctrl-Delete)


Perhaps something like this may work...

procedure TMyForm.FormCreate(Sender: TObject);
begin
    keyPreview := true; // set key preview on
end;

procedure TMyForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
// use either if or both; #8 = backspace, #127 = delete
//  if (Key = #8) then
//  if (Key = #127) then
    begin
        Key := #0;      // clear the key
        // Do your delete, maybe check that the control(s) you're concerned
with
        // do indeed have focus...
    end;
end;

Hope this helps,

\\stderr\\

Andrea B. <andr...@sedoc.it> wrote in article
<01bc8bf2$3abc59a0$58092dc3@dangib>...

Quote
> Hi!
> I have this problem:
> I want to delete a record in a TDBGrid simply by pressing the Delete key,
> and not the Ctrl-Delete.
> I tried to override the OnkeyPress event, without result.
> Any suggestion?

> Thanks in advance

> Andrea

Other Threads