Solved

Delete Records from DBGrid

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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