private void addToolButton_Click(object sender, EventArgs e) { using (var editQuestionForm = new EditQuestionForm()) { if (editQuestionForm.ShowDialog(this) == DialogResult.OK) { var question = new Question(); editQuestionForm.SaveTo(question); var db = Context.Instance; db.Questions.Add(question); db.SaveChanges(); Reload(); questionsData.ClearSelection(); var addedQuestionRow = questionsData.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => question.Equals(r.DataBoundItem)); if (addedQuestionRow != null) addedQuestionRow.Selected = true; } } }
private void EditRow() { var question = questionsData.CurrentRow != null ? questionsData.CurrentRow.DataBoundItem as Question : null; if (question == null) return; using (var editQuestionForm = new EditQuestionForm()) { editQuestionForm.LoadFrom(question); if (editQuestionForm.ShowDialog(this) == DialogResult.OK) { editQuestionForm.SaveTo(question); var db = Context.Instance; db.SaveChanges(); questionsData.InvalidateRow(questionsData.CurrentRow.Index); } } }