• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2304
  • Last Modified:

Delphi 7 :: TDBGrid :: Disable CTRL+DEL on Grid while allowing editing

Hi All,

I am using Delphi 7 with a TDBGrid component.

My application uses TActionList and I have created an action to handle my deletes.
This action item uses the shortcut key combination of: CTRL+D and I don't wish to change this.

On the DBGrid side, I would like to allow one to edit records directly in the grid but the grid should
not allow deletes except through my action. By default the grid also has a delete method implemented which is also assigned shortcut keys: CTRL+D. How can I disable this on the DBGrid?

Because like it is now, when pressing CTRL+DEL, my action gets fired first (this is correct) and deletes the current record (this is correct) and then secondly the grids delete method gets fired (don't want this) but if the record I am deleting is the last and only record then I obviously receives and error stating now records to delete because of the 2 delete methods trying to delete 1 record.

Please help.

Thanks!
0
Marius0188
Asked:
Marius0188
  • 2
  • 2
2 Solutions
 
SteveBayCommented:
You could try to prevent the delete in the Table's BeforeDelete event with something like this.
procedure TForm1.Table1BeforeDelete(DataSet: TDataSet);
begin
	If not MyGlobalDeleteFlag then
		Abort;
end;

Open in new window

0
 
rfwoolfCommented:
You can also do this:
(use the dbgrid's KeyDown event to disable use of Ctrl + Delete)
procedure Form1.DBGrid1KeyDown
   (Sender: TObject; var Key: Word; Shift:TShiftState) ;
begin
   if (Shift = [ssCtrl]) and (Key = VK_DELETE) then
     Key := 0; {ignore}
end;

Open in new window

0
 
rfwoolfCommented:
er,, just thinking, I don't know if that would cancel out your action or not... worth a try though.
0
 
SteveBayCommented:
rtwoolf,
 Yes, that will work as well.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now