Solved

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

Posted on 2007-11-22
4
2,033 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 105
Delphi 2 46
Delphi and Access based Enumeration 9 44
Installshield for Embarcadero EX 10.1 Berlin 4 14
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now