There are 2 buttoms (Add & Remove) when user clicks on add a new row gets added to the grid (using Grid.BeginInsert() method).Each row has a dropdown list in first column to select a role type and then in next column user selects the employee for that role. The business logic is if the user selects a role in a newly created row which already exist in the previously entered rows then this row should be invalidated and an error message is shown for that row (there are few other business logic as well).
I am calling following method
void
EditGrid_RowValidated(object sender, GridViewRowValidatedEventArgs e)
{
if (e.ValidationResults.Count == 0)
{
try
{
Validator.ValidateObject(e.Row.Item, new ValidationContext(e.Row.Item, null, null), true);
}
catch (ValidationException exp)
{
Telerik.Windows.Controls.GridViewCellValidationResult result = new GridViewCellValidationResult{ PropertyName = "OfficeName", ErrorMessage = exp.ValidationResult.ErrorMessage };
e.ValidationResults.Add(result);
}
}
}
Now when ever there is any error / violation of business rule the the error is shown against the row. But the problem is now if there is any error in the row and now user wants to delet the row, the validation happens each time and user is not able to perform any task. neither Add nor delete.
Please suggest how can i suppress the validation once it is done and error messages are shown to user. I dont want validation on grid to happen when user clicks Add/Delete. It should happen only while entering data in the row.