private void Context_ViewEdit(SubFormMode mode) { if (_View == TableView.User) { return; } try { var currRowIndex = dgvMain.SelectedCells[0].RowIndex; int currID = Convert.ToInt32(dgvMain.Rows[currRowIndex].Cells[0].Value); int currRowOnTop = dgvMain.FirstDisplayedScrollingRowIndex; var NextForm = new Form(); switch (_View) { case TableView.Supply: { NextForm = new ViewSupply(currID, mode); break; } case TableView.Good: { NextForm = new ViewGood(currID, mode); break; } case TableView.Car: { NextForm = new ViewCar(currID, mode); break; } case TableView.Storage: { NextForm = new ViewStorage(currID, mode); break; } case TableView.Employee: { NextForm = new ViewEmployee(currID, mode); break; } case TableView.Client: { NextForm = new ViewClient(currID, mode); break; } } NextForm.ShowDialog(); UpdateCurrentData(); dgvMain.FirstDisplayedScrollingRowIndex = currRowOnTop; dgvMain.Rows[currRowIndex].Selected = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BtnAdd_Click(object sender, EventArgs e) { int currRowIndex = -1; int currID; try { currRowIndex = dgvMain.SelectedCells[0].RowIndex; currID = Convert.ToInt32(dgvMain.Rows[currRowIndex].Cells[0].Value); } catch { } var NextForm = new Form(); switch (_View) { case TableView.Supply: { NextForm = new ViewSupply(); break; } case TableView.Good: { NextForm = new ViewGood(); break; } case TableView.Car: { NextForm = new ViewCar(); break; } case TableView.Storage: { NextForm = new ViewStorage(); break; } case TableView.Client: { NextForm = new ViewClient(); break; } case TableView.Employee: { NextForm = new ViewEmployee(); break; } } NextForm.ShowDialog(); int currRowOnTop = dgvMain.FirstDisplayedScrollingRowIndex; UpdateCurrentData(); try { dgvMain.FirstDisplayedScrollingRowIndex = currRowOnTop; dgvMain.Rows[currRowIndex].Selected = true; } catch { } }