Solved

Delete Records from DBGrid

Posted on 2002-07-28
6
200 Views
Last Modified: 2010-04-04
how do I delete a record from a dbgrid which is connected to a dataset?
0
Comment
Question by:sharol
6 Comments
 
LVL 1

Expert Comment

by:drnadeem
ID: 7183162
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids;

type
  TForm1 = class(TForm)
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Table1: TTable;
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 If Key = VK_Delete then
 begin
    if MessageDlg('Are you sure you want to delete this record ?',
    mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
    Table1.Delete;
    MessageDlg('Record has been deleted.', mtInformation,
      [mbOk], 0);

  end;
 end;
end;

end.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7183214
press [ctrl+del]
0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 7183235
But please, prevent the users errors, adding this code in the beforeDelete event of your Ttable:

if Application.MessageBox('¿Are you sure....?','Atención',mb_OkCancel + mb_IconQuestion)= idcancel then
abort;

I think that dgConfirmDelete (Options) is set to False, to avoid the not customize message.

Best Regards.
Marcos.
0
 

Expert Comment

by:CleanupPing
ID: 9342982
sharol:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9965989
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: kretzschmar

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

19 Experts available now in Live!

Get 1:1 Help Now