Solved

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

Posted on 2007-11-22
4
2,061 Views
Last Modified: 2013-11-23
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
Comment
Question by:Marius0188
  • 2
  • 2
4 Comments
 
LVL 14

Assisted Solution

by:SteveBay
SteveBay earned 250 total points
ID: 20334230
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
 
LVL 13

Accepted Solution

by:
rfwoolf earned 250 total points
ID: 20335246
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
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20335261
er,, just thinking, I don't know if that would cancel out your action or not... worth a try though.
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 20335465
rtwoolf,
 Yes, that will work as well.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 90
Magic Software info 18 131
Find and Replace Stream with 0s 8 62
PHP preg_replace code convert to Delphi 14 56
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question