?
Solved

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

Posted on 2007-11-22
4
Medium Priority
?
2,191 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 1000 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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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