public bool SetCellData(Week week, int course, string value) { int week_number; try { //if (!weeks.ContainsValue(week)) return false; week_number = weeks.First(x => Week.Compare(x.Value, week)).Key; int column_index = 0; foreach (DataGridViewCell cell in dataGridViewMonth.Rows[0].Cells) { int cell_value = Convert.ToInt32(cell.Value); if (cell_value == week_number) { column_index = cell.ColumnIndex; } } dataGridViewMonth.Rows[course + 2].Cells[column_index].Value = value; return(true); } catch { //MessageBox.Show("Ошибка заполнения ячейки"); return(false); } }