private void dataGridProduct_CellContentClick(object sender, DataGridViewCellEventArgs e) { string colName = dataGridProduct.Columns[e.ColumnIndex].Name; if (colName == "Edit") { frmProduct frmPro = new frmProduct(this); frmPro.btnSave.Enabled = false; frmPro.btnUpdate.Enabled = true; frmPro.txtPCode.Text = dataGridProduct.Rows[e.RowIndex].Cells[1].Value.ToString(); frmPro.txtBarcode.Text = dataGridProduct.Rows[e.RowIndex].Cells[2].Value.ToString(); frmPro.txtDescription.Text = dataGridProduct.Rows[e.RowIndex].Cells[3].Value.ToString(); frmPro.cboBrands.Text = dataGridProduct.Rows[e.RowIndex].Cells[4].Value.ToString(); frmPro.cboCategory.Text = dataGridProduct.Rows[e.RowIndex].Cells[5].Value.ToString(); frmPro.txtPrice.Text = dataGridProduct.Rows[e.RowIndex].Cells[6].Value.ToString(); frmPro.ShowDialog(); } else { if (MessageBox.Show("Are you sure to delete this product?", "Delete Product", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cn.Open(); cm = new SqlCommand("delete from tblproduct where pcode like '" + dataGridProduct.Rows[e.RowIndex].Cells[1].Value.ToString() + "'", cn); cm.ExecuteNonQuery(); cn.Close(); LoadProducts(); } } }
private void btnAddProduct_Click(object sender, EventArgs e) { frmProduct frmProduct = new frmProduct(this); frmProduct.btnSave.Enabled = true; frmProduct.btnUpdate.Enabled = false; frmProduct.LoadBrand(); frmProduct.LoadCategory(); frmProduct.ShowDialog(); }