As seen from the question it seems that the requirement is to validate the entry in the
TextBoxColumn
of
DataGridView
such that only
month
and
year
is entered. For this purpose I think the the
CellValidating
event of
DataGridView
can be used as follows:
dataGridView1.CellValidating += (s, args) => {
if (args.ColumnIndex != 2)
return;
if (!Regex.IsMatch((string)args.FormattedValue,@"\d{2}/\d{4}", RegexOptions.CultureInvariant)){
MessageBox.Show("Please enter month and year as 05/2012");
args.Cancel=true;
}
};
In the above example the
MM/yyyy
format is used. You can check any other format including the valid ranges with appropriate regular expression pattern.