ActionOnLostFocus CommitEdit if Validation passes else CancelEdit

6 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 06 Jan 2012 Link to this post

    I've been looking through the threads on canceling a new or edited row/cell on validation and I can't seem to come up with a good solution.

    The best way is if I could have a button to mimic the the 'Esc' key does.  Only problem with is I can't press a button when in validation mode.  And there's no way my users will remember to use the 'Esc' key.

    I can't use ActionOnLostFocus=CancelEdit, because sometimes I want to hit the save button and keep those rows that haven't been committed. And if they are valid and I go somewhere else I want to keep them.

    I tried to use ActionOnLostFocus in combination with ValidatesOnDataErrors, but that doesn't really give me what I want.
  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 09 Jan 2012 Link to this post

    Hello Dan,

    Could you try to set ActionOnLostFocus property to "None" ? Thus the changed will be neither committed, nor cancelled and you will be able to perform the required logic in the button's click event.
    Is that approach suitable for your scenario ? 

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 09 Jan 2012 Link to this post

    Yeah, I guess that will work.
    I just saw on the gridview.  There is a 'RowInEditMode'.  I just have to validate that row.  If the row passes, then commitEdit, if not cancel the edit.  This is a lot of work for a lot of Grids.

    Edit: This is working except 'RowInEditMode' can't see the current cell that I'm on.  So after I put in a value and click save it fails the validation because it doesn't see my current cell.  Is there a way to commit this current cell?

    I wish you could add something like CommitOnValidationTrue.

    EDIT AGAIN:
    Ok, I think I got the right combo now.  If I set the ActionOnLostFocus to 'None', then when I press my 'Save' button.  I  commit by gridview
    myGridView.CommitEdit();  Then I check if it has a RowInEditMode != null.  If there is a still row in edit mode then it failed validation.  There is also a isvalid property.
    myGridView.CommitEdit();
         if (myGridView.RowInEditMode != null)
          {
               //There are failed validations
     
          }
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Jan 2012 Link to this post

    Hi Dan,

    Based on your last post, I am not quite capable of understanding whether you resolved the issues you have or not. Do you still have any troubles or you find the most appropriate for your scenario solution ?  
    Let me know in case you need any assistance.

    Regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 10 Jan 2012 Link to this post

    Yeah, it's working with the combination that I used above.  Thanks.
  7. Alden
    Alden avatar
    1 posts
    Member since:
    May 2012

    Posted 14 Nov 2013 Link to this post

    Thanks, I was having the same issue.

    Client wants a grid that they can edit several different rows and cells in without commuting changes until they are ready.
Back to Top
DevCraft banner