У меня есть таблица Timetable, которая представлена в виде DataGrid. В нем есть столбец "Date". Я хочу чтобы можно было вводить в этот столбец только дату не раньше текущей. Вот что я пробовал сделать, но это не работает. Подскажите как можно модифицировать код
private void timetableDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
string headerText = timetableDataGridView.Columns[e.ColumnIndex].HeaderText;
if (!headerText.Equals("Date")) return;
DateTime date;
if (!DateTime.TryParse(e.FormattedValue.ToString(), out date) && date > System.DateTime.Now)
{
timetableDataGridView.Rows[e.RowIndex].ErrorText = "attention";
e.Cancel = true;
}
}
void timetableDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
// Clear the row error in case the user presses ESC.
timetableDataGridView.Rows[e.RowIndex].ErrorText = String.Empty;
}
DateTime.Compare