private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { string colName = dataGridView1.Columns[e.ColumnIndex].Name; if (colName == "Edit") { AdminAddSupplier sup = new AdminAddSupplier(this); sup.lblID.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); sup.txtSupplierName.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); sup.txtSupplierAddress.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); sup.txtSupplierPhone.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); sup.txtSupplierTelephone.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); sup.BtnUpdate.Focus(); sup.BtnSave.Enabled = false; sup.BtnUpdate.Enabled = true; sup.lbl1.Text = "Update Supplier"; sup.BtnSave.Visible = false; sup.BtnUpdate.Visible = true; sup.Show(); } else if (colName == "Delete") { if (MessageBox.Show("Are you sure you want to delete this Supplier", "Deleting Supplier", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cn.Open(); cm = new SqlCommand("DELETE FROM tblSupplier WHERE id like '" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "'", cn); cm.ExecuteNonQuery(); cn.Close(); MessageBox.Show("Record has been successfully Deleted", "Supplier Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowSuppliers(); } } }
private void BtnAddSupplier_Click(object sender, EventArgs e) { AdminAddSupplier sup = new AdminAddSupplier(this); sup.BtnSave.Visible = true; sup.BtnSave.Location = new System.Drawing.Point(112, 413); sup.BtnUpdate.Visible = false; sup.BtnUpdate.Enabled = false; sup.BtnSave.Enabled = true; sup.Show(); }