예제 #1
0
        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;
                }
            }
        }
예제 #2
0
 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);
         }
     }
 }