Click here to Skip to main content
13,088,846 members (54,419 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi friends

This is my code for deleting row of data in datagridview.
private void appdatagrid1_KeyDown(object sender, KeyEventArgs e)
           if (e.KeyCode == Keys.Delete && appdatagrid1.CurrentRow.Selected)
               DialogResult result = MessageBox.Show("Do You Want to Delete" + "if deleted,then data will be permenantely deleted from database", "Warining", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
               if (result == DialogResult.OK)
                   comp.APPLICATIONNUMBER = Convert.ToInt32(appdatagrid.CurrentRow.Cells["ApplicationNumber"].Value);
                   bool result1 = inter.deleteapplicationfromstage1(comp);
                   if (result1)
                       MessageBox.Show("Data successfully Deleted");
                       MessageBox.Show("Deletion Failed");
               else if(result==DialogResult.Cancel)
              // comp.APPLICATIONNUMBER = Convert.ToInt32(appstage1grid.CurrentRow.Cells["ApplicationNumber"].Value);
               //bool result = inter.deleteapplicationfromstage1(comp);

preload() is a method that retrieve the data from database for gridview.what is my problem is when i select a row and press a delete button for deleting a row (i am using this keydown event in delete button).but in this event, even i cancel the delete of record,the particular row of the datagridview is deleted in view not in the database. In dialogresult i am using preload1() method for retrieving data from database.the gridview is updated with fresh data,but the deleted row is not available in view. how to solve this.
Posted 19-Feb-13 7:59am
Updated 19-Feb-13 17:56pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100