private void taskEditButton_Click(object sender, EventArgs e) { int selectedrowindex = taskDataGridView.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = taskDataGridView.Rows[selectedrowindex]; string taskNameFromGrid = Convert.ToString(selectedRow.Cells["tasknameDataGridViewTextBoxColumn"].Value); if (taskNameText.Text == "") { MessageBox.Show("Please select a record to update.", "Update Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (taskDescText.Text == "" || taskContactsListDropDown.SelectedIndex == -1) { MessageBox.Show("Mandatory field(s) required.", "Update Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (taskNameText.Text != taskNameFromGrid) { MessageBox.Show("Please re-select the correct record. " + Environment.NewLine + Environment.NewLine + "Selected record and displayed informations are diefferent" + Environment.NewLine + Environment.NewLine + "(HINT: Try clicking different column or try double click different column)", "Delete Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (!(taskOneoffRButton.Checked) && !(taskMonthlyRButton.Checked) && !(taskWeeklyRButton.Checked) && !(taskYearlyRButton.Checked) == true) { MessageBox.Show("Please select category.", "Update Status", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (taskOneoffRButton.Checked) { taskCategoryRButton = taskOneoffRButton.Text; } else if (taskMonthlyRButton.Checked) { taskCategoryRButton = taskMonthlyRButton.Text; } else if (taskWeeklyRButton.Checked) { taskCategoryRButton = taskWeeklyRButton.Text; } else if (taskYearlyRButton.Checked) { taskCategoryRButton = taskYearlyRButton.Text; } else { Console.WriteLine("Error in category selection."); } if (taskAdditionalText.Text == "" || taskAdditionalText.Text == null) { taskAdditionalText.Text = "N/A"; } else if (taskLocationText.Text == "" || taskLocationText.Text == null) { taskLocationText.Text = "N/A"; } else if (taskPriorityDropDown.Text == "" || taskPriorityDropDown.Text == null) { taskPriorityDropDown.Text = "None"; } else { cc.TaskName = taskNameText; cc.TaskDueDate = taskDueDateBox; cc.TaskTimeFrom = taskTimeFromTBox; cc.TaskTimeTo = taskTimeToTBox; cc.TaskLocation = taskLocationText; cc.TaskDescription = taskDescText; cc.TaskAdditionalNote = taskAdditionalText; cc.TaskPriorityLevel = taskPriorityDropDown; cc.TaskContact = taskContactsListDropDown; cc.TaskCategory = taskCategoryRButton; cc.TaskDataGridView = taskDataGridView; cc.updateTask(); taskNameText.Enabled = true; taskNameText.Text = ""; taskDueDateBox.Text = ""; taskTimeFromTBox.Text = ""; taskTimeToTBox.Text = ""; taskContactsListDropDown.Text = ""; taskLocationText.Text = ""; taskDescText.Text = ""; taskCategoryRButton = ""; taskAdditionalText.Text = ""; taskPriorityDropDown.Text = ""; } } }