void TasksDataGrid_CellClick(object sender, DataGridViewCellEventArgs e) { // If click new row or header if (e.RowIndex == tasksDataGrid.NewRowIndex || e.RowIndex < 0) { return; } if (e.ColumnIndex == tasksDataGrid.Columns["dataGridViewDeleteButtonColumn"].Index) { if (MessageBox.Show("Are you sure you want to delete this task?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var taskId = e.RowIndex; TimerUtils.DisposeTimers(taskId); Repository.DeleteTaskById(taskId); GridUtils.UpdateGrid(); } } else if (e.ColumnIndex == tasksDataGrid.Columns["dataGridViewStartButtonColumn"].Index) { var taskId = e.RowIndex; var task = Repository.GetTaskById(taskId); if (task == null) { MessageBox.Show("Internal error. Task could not be found."); return; } if (ProcessUtils.IsProcessRunning(task)) { MessageBox.Show("Task is already running."); return; } TimerUtils.DisposeTimers(task); TaskStarter.GridStarter(task); GridUtils.UpdateGrid(); } }