Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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");
                       preload1();
                   }
                   else
                   {
                       MessageBox.Show("Deletion Failed");
                   }
               }
               else if(result==DialogResult.Cancel)
               {
                   preload1();
               }
              // 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 8:59am
Edited 19-Feb-13 18:56pm
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 315
2 Maciej Los 285
3 Peter Leow 260
4 CPallini 180
0 Sergey Alexandrovich Kryukov 7,138
1 OriginalGriff 5,577
2 Peter Leow 4,097
3 Mika Wendelius 2,850
4 CHill60 2,818


Advertise | Privacy | Mobile
Web02 | 2.8.150224.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
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