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

ActionOnLostFocus CommitEdit if Validation passes else CancelEdit

5 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 07 Jan 2012, 05:35 AM
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.

5 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 09 Jan 2012, 07:57 AM
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 >>

0
danparker276
Top achievements
Rank 2
answered on 09 Jan 2012, 10:05 PM
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
 
      }
0
Maya
Telerik team
answered on 10 Jan 2012, 07:45 AM
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 >>

0
danparker276
Top achievements
Rank 2
answered on 10 Jan 2012, 07:55 AM
Yeah, it's working with the combination that I used above.  Thanks.
0
Alden
Top achievements
Rank 1
answered on 15 Nov 2013, 12:35 AM
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.
Tags
GridView
Asked by
danparker276
Top achievements
Rank 2
Answers by
Maya
Telerik team
danparker276
Top achievements
Rank 2
Alden
Top achievements
Rank 1
Share this question
or