Solved

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

Posted on 2007-11-22
4
2,120 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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