Solved

Delete Records from DBGrid

Posted on 2002-07-28
6
202 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

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

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 article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

13 Experts available now in Live!

Get 1:1 Help Now