示例#1
0
 private void dgvProducts_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         if ((MessageBox.Show("Are you sure you wish to delete the selected product data?", "Confirm", MessageBoxButtons.YesNo)) == DialogResult.Yes)
         {
             int id = Convert.ToInt32(dgvProducts.Rows[dgvProducts.CurrentCell.RowIndex].Cells[0].FormattedValue.ToString());
             GeneralMethods.DeleteProduct(id);
             MessageBox.Show("The data has been deleted successfully!", "Success");
             ProductsData.DataSource = GeneralMethods.GetProducts();
         }
     }
 }