Hi,
using cellvalidating event youcan validate the cell.
i hope it will help you
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "";
DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell.IsInEditMode)
{
if (e.FormattedValue == null || e.FormattedValue.ToString() == string.Empty)
{
return;
}
else
{
string name = (string)e.FormattedValue;
Match match = Regex.Match(name, @"^[0-9\s]*$");
if (match.Value == string.Empty)
{
e.Cancel = true;
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Please Enter The Valid Phone No";
}
if (match.Value.Length > 25)
{
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Please Enter The Valid Phone No";
e.Cancel = true;
}
}
}
}
Best Regards,
C.Gnanadurai
-----------------------
Please mark the post as answer if it is helpfull to you