/// <summary> /// inserting values to textbox by clicking on datagris /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView_U_M_DoubleClick(object sender, EventArgs e) // poplate text box when data grid being pressed { if (dataGridView_U_M.CurrentRow.Index != -1) { model_t_ItemU_M.ID = Convert.ToInt32(dataGridView_U_M.CurrentRow.Cells["M_U_ID"].Value); using (testDBEntities db = new testDBEntities()) { model_t_ItemU_M = db.t_ItemU_M.Where(x => x.ID == model_t_ItemU_M.ID).FirstOrDefault(); textBox_ItemU_M.Text = model_t_ItemU_M.ItemU_M; } } }
public void Del_U_M_Record(t_ItemU_M model_t_ItemU_M, TextBox textBox_ItemU_M, DataGridView dataGridView_U_M) { if (MessageBox.Show("Are You Sure to Delete this Record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (testDBEntities db = new testDBEntities()) { var entry = db.Entry(model_t_ItemU_M); if (entry.State == EntityState.Detached) { db.t_ItemU_M.Attach(model_t_ItemU_M); } db.t_ItemU_M.Remove(model_t_ItemU_M); db.SaveChanges(); ClearDataGridView_t_ItemU_M(textBox_ItemU_M); populateDataGridView_t_ItemU_M(dataGridView_U_M); MessageBox.Show("Deleted Successfully"); } } }