private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { con.Open(); int URow = int.Parse(e.RowIndex.ToString()); int URowIndex = int.Parse(e.ColumnIndex.ToString()); ID = Convert.ToInt32(dataGridView1.Rows[URow].Cells[0].Value.ToString()); if (URowIndex == 4) { if (URowIndex == 0) { MessageBox.Show("Click on delete button"); } if (URowIndex != 0) { var askfirst = MessageBox.Show("Are you sure you want to delete this?", "Delete", MessageBoxButtons.YesNo); if (askfirst == DialogResult.Yes) { cmd = new SqlCommand("DELETE FROM Evaluation where ID = @Id", con); cmd.Parameters.AddWithValue("@Id", ID); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Deleted Succesfully"); this.Hide(); Evaluation f1 = new Evaluation(); f1.ShowDialog(); this.Close(); } else { this.Hide(); Evaluation f1 = new Evaluation(); f1.ShowDialog(); this.Close(); } } } else if (URowIndex == 5) { int d1 = (int)dataGridView1.CurrentRow.Cells[0].Value; if (URowIndex == 0) { MessageBox.Show("Click again"); } if (URowIndex != 0) { var askfirst1 = MessageBox.Show("Are you sure you want to Update this?", "Update", MessageBoxButtons.YesNo); if (askfirst1 == DialogResult.Yes) { Flag3 = d1; textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); con.Close(); } else { con.Close(); this.Hide(); Evaluation f2 = new Evaluation(); f2.ShowDialog(); } } } else { con.Close(); } }