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

Validation When Comparing Two Column Values

1 Answer 225 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt Leeds
Top achievements
Rank 1
Matt Leeds asked on 22 Aug 2012, 08:05 PM
We have a situation in the grid where we have a start date column and an end date column.  Our validation routine says that the start date must be earlier than the end date.  However, we must suppose that the user might want to change both the start date and the end date, and simply begin by changing the start date.  This can lead to the start date being later than the end date, but only temporarily.  

The problem is that the validation gets triggered, and then the user can't move the active cell to the end date to make it conform to the validation.  To get out of this trap, they must change the start date back, go change the end date, then finally again change the start date to whatever they wanted.

I think one way to solve this would be to be able to turn off the strict enforcement of the validation to allow the user to move out of the offending cell.  Is this possible?  Do you have a different suggestion?

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 28 Aug 2012, 08:05 AM
Hi Matt,

 In order to resolve your issue you can validate the data on row level using the RowValidating event. The RowValidating event is a very similar to the CellValidating event. However, instead of getting an individual cell, you have the entire row.  

private void radGridView1_RowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e)
  {
      if ((e.Row.Item as Club).StartDate > (e.Row.Item as Club).EndDate)
      {
          e.IsValid = false;
          var result = new Telerik.Windows.Controls.GridViewCellValidationResult();
          result.ErrorMessage = "Start date should be before End date";
          e.ValidationResults.Add(result);
      }
  }


For more information about the RowValidating event please check this help article.

Kind regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Matt Leeds
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or