RD Design

RD Design

  • NA
  • 25
  • 26.7k

Datagridview cell validation not working?

Mar 13 2015 5:47 AM
Hi,
I have a c# datagridview and I need to do some validation for cells before insert and update.here is my code.My issue is CellValidating is not firing up.
Can anyone show me the issue with code?

private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "OrderNo")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText =
"Order No must not be empty";
e.Cancel = true;
}
}
}

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}

Thanks

Answers (3)