private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { String colname = dataGridView1.Columns[e.ColumnIndex].Name; if (colname == "Edit") { FormBrand frm = new FormBrand(this); frm.btnSave.Enabled = false; frm.btnUpdate.Enabled = true; frm.lblID.Text = dataGridView1[1, e.RowIndex].Value.ToString(); frm.textBoxBrand.Text = dataGridView1[2, e.RowIndex].Value.ToString(); frm.ShowDialog(); } else if (colname == "Delete") { if (MessageBox.Show("You want to remove this Brand?", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cn.Open(); cm = new SqlCommand("delete from tableBrand where id like '" + dataGridView1[1, e.RowIndex].Value.ToString() + "'", cn); cm.ExecuteNonQuery(); cn.Close(); MessageBox.Show("Brand removed sucessfully.", "Removed", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadRecords(); } } }
private void btnCreateNew_Click(object sender, EventArgs e) { FormBrand frm = new FormBrand(this); frm.Show(); }