Important alert: (current site time 7/16/2013 5:03:48 AM EDT)
 

VB icon

MultiDelete/Recall on DBGrid Records

Email
Submitted on: 12/20/2001 11:36:19 PM
By: VICKY  
Level: Advanced
User Rating: Unrated
Compatibility: Delphi 5, Delphi 4, Pre Delphi 4
Views: 12550
author picture
(About the author)
 
     After we will Display table records on DBgrid, we usually use navigator to control DBgrid records.So for Delete & Recall functions which will delete only one record at a time. My code can do Multiple Records Delete and Multiple deleted Records Recall at a time.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
!**************************************
! Name: MultiDelete/Recall on DBGrid Records
! Description:After we will Display table records on DBgrid, we usually use navigator to control DBgrid records.So for Delete & Recall functions which will delete only one record at a time. My code can do Multiple Records Delete and Multiple deleted Records Recall at a time.
! By: VICKY
!
! Inputs:DBGrid proferties:-Options-MultiSelect=True
!
! Returns:will delete the record from grid
!
! Side Effects:need to put grid display color if record deleted the display some gray...like that.if not normal color.
!
!This code is copyrighted and has! limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=541&lngWId=7!for details.!**************************************

var i: integer;
begin
 if MessageDlg('Recall Selected Record(s)?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
 begin
with wwdbgrid1,wwdbgrid1.datasource.dataset do begin
 DisableControls;
 for i:=0 to SelectedList.count-1 do begin
 GotoBookmark(selectedlist.items[i]) ;
 FreeBookmark(selectedlist.items[i]) ;
 MailInApollo.Recall;
 end; //
 selectedlist.clear;
 EnableControls;
 end; //
 end; // msgdlg
procedure TInBoxForm.Delete1Click(Sender: TObject);
var i:integer;
begin
if MessageDlg('Delete Selected Record(s)?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
TRY
TrashBoxTable.open;
EXCEPT
on EDatabaseError do
 begin
 Showmessage('Cannot open TRASHBOX !');
 EXIT
 end;
END;
with wwdbgrid1,wwdbgrid1.datasource.dataset do begin
 DisableControls;
 for i:=0 to SelectedList.count-1 do begin
 GotoBookmark(selectedlist.items[i]) ;
 FreeBookmark(selectedlist.items[i]) ;
 MainForm.UpdRecord(wwdbgrid1.datasource.dataset, TrashboxTable,True);
 TrashboxTable.edit;
 TrashboxTable.fieldbyName('Type').asstring:='I';
 TrashboxTable.fieldbyName('Date').asdatetime:=
 MailInTable.fieldbyName('Date_recv').asdatetime;
 TrashboxTable.post ;
 Delete;
 end; //
 TrashboxTable.close;
 selectedlist.clear;
 EnableControls;
end; //
end;
end;


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

2/6/2002 11:25:49 AMEd

You should always wrap the DisableControls in a try finally, and have the Enable in the finally block. That way it will always be called, and avoid a lockup.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.