Click here to Skip to main content
15,905,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void dgvGroupDet_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dgvGroupDet.Columns[e.ColumnIndex].Name == "Name")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dgvGroupDet.Rows[e.RowIndex].ErrorText =
"Name must not be empty";
e.Cancel = true;
}
}
}
private void dgvGroupDet_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dgvGroupDet.Rows[e.RowIndex].ErrorText = String.Empty;
}
Note: I m trying to do this code for validation in datagridview it will work complete but due to validation i can't close my Form.
Posted

1 solution

Create a boolean property and call it IsClosing and set it to true ONLY when the form is closing. The FormClosing event of the form should be where you would set it to true.

Now, at the CellValidating() event method, check if the form is closing. If it is, simply return. No need for validation.

:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900