private void btnNew_Click(object sender, EventArgs e) { Form form = new frmChild_BookTitle(0); switch (TypeOfSearch) { case 0: form = new frmChild_BookTitle(0); break; case 1: form = new frmChild_Author(0); break; case 2: form = new frmChild_Category(0); break; case 3: form = new frmChild_User(0); break; case 4: form = new frmChild_Book(0); break; case 5: form = new frmChild_Inventory(0); break; } form.MdiParent = this.MdiParent; form.FormClosing += (object sender1, FormClosingEventArgs ee) => { if (form.DialogResult == DialogResult.OK) { //MessageBox.Show("OK!"); LoadData(); } }; form.Show(); /**DialogResult r = form.ShowDialog(); * if (r == DialogResult.OK) * { * LoadData(); * } **/ }
private void btnUpdate_Click(object sender, EventArgs e) { Form form = new frmChild_BookTitle(1); int selectedrowindex = 0; DataGridViewRow selectedRow = null; try { selectedrowindex = dgvSearch.SelectedCells[0].RowIndex; selectedRow = dgvSearch.Rows[selectedrowindex]; List <String> list = new List <string>(); //MessageBox.Show(selectedRow.Cells[0].Value.ToString()); if (selectedRow.Cells[0].Value != null && selectedRow.Cells[0].Value.ToString() != string.Empty) { //value = (string)selectedRow.Cells[0].Value; foreach (DataGridViewCell cell in selectedRow.Cells) { if (cell.Value != null) { list.Add(cell.Value.ToString()); } else { list.Add(""); } } switch (TypeOfSearch) { case 0: form = new frmChild_BookTitle(1, list); break; case 1: form = new frmChild_Author(1, list); break; case 2: form = new frmChild_Category(1, list); break; case 3: form = new frmChild_User(1, list); break; case 4: form = new frmChild_Book(1, list); break; case 5: form = new frmChild_Inventory(1, list); break; } form.MdiParent = this.MdiParent; form.FormClosing += (object sender1, FormClosingEventArgs ee) => { if (form.DialogResult == DialogResult.OK) { LoadData(); } }; form.Show(); } else { MessageBox.Show(this, "Can not update null cells", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Choose to update"); } /** * DialogResult r = form.ShowDialog(); * if (r == DialogResult.OK) * { * LoadData(); * } **/ }