private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if (dataGridView1.Columns[e.ColumnIndex].Name == "delete") { if (MessageBox.Show("Are You Sure You Want to Delete this Product\nfrom Database", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) { int ProductID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value); ProduitDAO pdo = new ProduitDAO(); if (pdo.RemoveProduitbyId(ProductID)) { dataGridView1.Rows.RemoveAt(e.RowIndex); } else if (pdo.RemoveProduitbyId(ProductID)) { MessageBox.Show("Product Not Deleted"); } } } else if (dataGridView1.Columns[e.ColumnIndex].Name == "edit") { int ProductID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id"].Value); string ProductName = dataGridView1.Rows[e.RowIndex].Cells["nom"].Value.ToString(); decimal ProductPrice = Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells["prix"].Value.ToString()); string ProductCategory = dataGridView1.Rows[e.RowIndex].Cells["categorie"].Value.ToString(); string ProductDescription = dataGridView1.Rows[e.RowIndex].Cells["description"].Value.ToString(); byte[] ProductPicture = (byte[])dataGridView1.Rows[e.RowIndex].Cells["image"].Value; UpdateProduit UpdateProductForm = new UpdateProduit(ProductID, ProductName, ProductPrice, ProductCategory, ProductDescription, ProductPicture); if (UpdateProductForm.ShowDialog() == DialogResult.OK) { ProduitDAO pdo = new ProduitDAO(); Produit UpdatedProductDetail = pdo.Find(ProductID); dataGridView1.Rows[e.RowIndex].Cells["nom"].Value = UpdatedProductDetail.Nom; dataGridView1.Rows[e.RowIndex].Cells["prix"].Value = UpdatedProductDetail.Prix; dataGridView1.Rows[e.RowIndex].Cells["categorie"].Value = UpdatedProductDetail.IdCat.Nom; dataGridView1.Rows[e.RowIndex].Cells["description"].Value = UpdatedProductDetail.Description; dataGridView1.Rows[e.RowIndex].Cells["image"].Value = UpdatedProductDetail.Img; } } } }