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