Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 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

15 Experts available now in Live!

Get 1:1 Help Now