/// <summary> /// Handles the Click event of the Add_Button control, create Add dialog object. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Add_Button_Click(object sender, EventArgs e) { QuestionAttributes Add = new QuestionAttributes(DataBase); Add.ShowDialog(); Update();//update data grid view with new data when add dialog close }
/// <summary> /// Handles the Click event of the Edit_Button control, create Edit dialog object. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Edit_Button_Click(object sender, EventArgs e) { try { if (!IsListEmpty())//check if list box is empty to return index of selected row { if (DatabaseListBox.SelectedIndices.Count == 1) { Create_Question(); QuestionAttributes Edit = new QuestionAttributes(question, DataBase); Edit.ShowDialog(); Update();//update data grid view with new data when add dialog close } else if (DatabaseListBox.SelectedIndices.Count == 0) { MessageBox.Show("No question selected", "Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Error);//in case database is empty Print_Errors("No question selected"); } else { MessageBox.Show("Please select one question to edit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors("Please select one question to edit"); } } else { MessageBox.Show("No questions to edit", "Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Error);//if data grid view or database contian no records Print_Errors("No questions to edit"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Print_Errors(ex.Message, ex); } }