This is a migrated thread and some comments may be shown as answers.

[Solved] Grid Validation

0 Answers 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sonu
Top achievements
Rank 1
Sonu asked on 25 Jan 2011, 01:30 PM
Hi

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.

Tags
GridView
Asked by
Sonu
Top achievements
Rank 1
Share this question
or