Validation When Comparing Two Column Values

2 posts, 0 answers
  1. Matt Leeds
    Matt Leeds avatar
    12 posts
    Member since:
    Apr 2010

    Posted 22 Aug 2012 Link to this post

    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?
  2. Yoan
    Yoan avatar
    1182 posts

    Posted 28 Aug 2012 Link to this post

    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";

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

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top