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
Loading
Resign DesignsPosted Mar 15, 2015, 12:08 AM
private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 0)
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText =
"Line No must not be empty";
e.Cancel = true;
}
else if (e.ColumnIndex == 0)
{
int i;
if (!int.TryParse(Convert.ToString(e.FormattedValue), out i))
{
dataGridView1.Rows[e.RowIndex].ErrorText =
"Only numeric values for Line No";
e.Cancel = true;
}
}
}
Resign DesignsPosted Mar 14, 2015, 12:08 AM
Vithal WadjePosted Mar 13, 2015, 2:58 PM