private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) { string collName = dataGridView2.Columns[e.ColumnIndex].Name; if (collName == "Edit" && e.RowIndex > 0) { formBrand frm = new formBrand(this); frm.btnSave.Visible = false; frm.btnUpdate.BackColor = Color.FromArgb(20, 158, 132); frm.btnUpdate.ForeColor = Color.White; frm.LabelText = dataGridView2[e.ColumnIndex, 1].Value.ToString(); DataGridViewRow row = dataGridView2.Rows[e.RowIndex]; frm.LabelText = row.Cells[2].Value.ToString(); frm.lbliD.Text = row.Cells[1].Value.ToString(); frm.ShowDialog(); } if (collName == "Delete" && e.RowIndex > 0) { if (MessageBox.Show("Are you sure you want to save this brand?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cn.Open(); cm = new SqlCommand("DELETE FROM brand where id =@id", cn); DataGridViewRow row = dataGridView2.Rows[e.RowIndex]; string id = row.Cells[1].Value.ToString(); cm.Parameters.AddWithValue("@id", id); cm.ExecuteNonQuery(); cn.Close(); LoadRecords(); MessageBox.Show("Brand deleted sucessfully"); } } }
private void pictureBox2_Click(object sender, EventArgs e) { formBrand fb = new formBrand(this); fb.btnUpdate.Visible = false; fb.ShowDialog(); }