private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == EditCol.Index) //Edit { EditID = int.Parse(dgv.CurrentRow.Cells["ID"].Value.ToString()); var con = CONN.GetById(EditID); txt01.Text = con.txt2; txt02.Text = con.txt3; txt03.Text = con.txt4; txt05.Text = con.txt6; txt06.Text = con.txt7; cmb08.Text = con.txt8; cmb07.Text = con.txt9; txt09.Text = con.txt10; txt10.Text = con.txt11; cmb12.Text = con.txt13; cmb18.Text = con.txt19; btnSave.Text = "ذخیره تغییرات"; } if (e.ColumnIndex == DelCol.Index) //Del { if (MessageBox.Show("آیا مایلید کالای مورد نظر حذف شود؟" , "Delete" , MessageBoxButtons.YesNo , MessageBoxIcon.Question , MessageBoxDefaultButton.Button2 ) == DialogResult.Yes) { try { CONN.Delete(int.Parse(dgv.CurrentRow.Cells["ID"].Value.ToString())); dgv.DataSource = CONN.GetAllData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
private void dgvKala_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == KalaEditCol.Index) //Edit { try { cmbContainerNumber.Enabled = false; KalaEditID = int.Parse(dgvKala.CurrentRow.Cells["KALA_ID"].Value.ToString()); var conn = CONN.GetById(KalaEditID); cmbContainerNumber.Text = conn.CTRNo; txt01.Text = conn.txt2; txt02.Text = conn.txt3; txt03.Text = conn.txt4; txt05.Text = conn.txt6; txt06.Text = conn.txt7; cmb08.Text = conn.txt8; cmb07.Text = conn.txt9; txt09.Text = conn.txt10; txt10.Text = conn.txt11; txt11.Text = conn.txt12; cmb12.Text = conn.txt13; cmb18.Text = conn.txt19; btnSaveKala.Text = "ذخیره تغییرات"; } catch (Exception ex) { MessageBox.Show("خطا در خواندن اطلاعات\nError: " + ex.Message); } } if (e.ColumnIndex == KalaDelCol.Index) //Del { if (MessageBox.Show("آیا مایلید کالای مورد نظر حذف شود؟" , "Delete" , MessageBoxButtons.YesNo , MessageBoxIcon.Question , MessageBoxDefaultButton.Button2 ) == DialogResult.Yes) { try { CONN.Delete(int.Parse(dgvKala.CurrentRow.Cells["KALA_ID"].Value.ToString())); if (dgvKala.Rows.Count == 0) { progressBar3.Value = 50; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dgvKala.DataSource = null; dgvKala.DataSource = CONN.GetAllData(); } } } }