private void Edit_toolStripButton2_Click(object sender, EventArgs e) { //редактировать if (this.phoneBookGridListDataGridView.SelectedRows.Count > 0) { var rowIndex = phoneBookGridListDataGridView.SelectedRows[0].Index;//сохраняем фокус на текущую строку AddPhoneBookForm form2 = new AddPhoneBookForm(PhoneBookList, phoneBookGridListDataGridView.SelectedRows[0].Index); DialogResult dr = form2.ShowDialog(); if (dr == DialogResult.Cancel) { CopyListToGrid(); } phoneBookGridListDataGridView.Rows[rowIndex].Selected = true; } else { var rowIndex = phoneBookGridListDataGridView.CurrentCell.RowIndex; //сохраняем фокус на текущую строку AddPhoneBookForm form2 = new AddPhoneBookForm(PhoneBookList, phoneBookGridListDataGridView.CurrentCell.RowIndex); DialogResult dr = form2.ShowDialog(); if (dr == DialogResult.Cancel) { CopyListToGrid(); } phoneBookGridListDataGridView.Rows[rowIndex].Selected = true; } }
private void Add_toolStripButton1_Click(object sender, EventArgs e) { AddPhoneBookForm form2 = new AddPhoneBookForm(PhoneBookList); DialogResult dr = form2.ShowDialog(); if (dr == DialogResult.Cancel) { CopyListToGrid(); } phoneBookGridListDataGridView.Rows[phoneBookGridListDataGridView.RowCount - 1].Selected = true; }