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

InvalidOperationException on saving invalid new row

1 Answer 55 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Scott Waye asked on 07 Jul 2012, 09:01 AM
Hi,

Using Q1 2012, and RIA services.  I bind a EntityCollectionView to the RadGridView and allow the user to add new rows using the built in functionality.  Everything works fine under normal use.  The entity has a mandatory first field, so when the user clicks to add a new row immediately the first field is in error and the row is marked in error.  If the user then tries to submit changes using a save buttom outside the grid, it doesn't work and none of my code is executed as the row is in error.  This is good and again no problem up to here.  The user can repeatedly try to click save and nothing happens (which is correct), however if the user clicks the save button very fast, like a double click, the save code is executed for some reason and of course when submitchanges is executed on the RIA context you get this exception as the row is still in edit.  Note that I have no double click code defined and this is the stack trace:

   at System.ServiceModel.DomainServices.Client.Entity.VerifyNotEditing()
   at System.ServiceModel.DomainServices.Client.EntityChangeSet.Validate(ValidationContext validationContext)
   at System.ServiceModel.DomainServices.Client.DomainContext.ValidateChangeSet(EntityChangeSet changeSet, ValidationContext validationContext)
   at System.ServiceModel.DomainServices.Client.DomainContext.SubmitChanges(Action`1 callback, Object userState)
   at TheHub.Silverlight.Commands.SaveCommand.Execute(Object parameter)

Please could you explain what the mechanism is that prevents the save button's command Execute method being called when a row in the grid is in error as this may explain why double clicking the button somehow bypasses this mechanism?

Thanks,

Scott

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 11 Jul 2012, 06:36 AM
Hi,

I'll try to explain what is causing the problem. When RadGridView is in edit mode and control outside RadGridView gets focus (as clicking on a "Save" button), RadGridView takes the action according to its ActionOnLostFocus property (by default this action is CommitEdit). CommitEdit actually performs cell and row validation before committing the edit and if there is a problem returns focus to the invalid cell (row). However some delay may by-pass this mechanism. You can hook for RadGridView.RowValidatED event and if the row is not valid to stop the save process.

Greetings,
Nedyalko Nikolov
the Telerik team

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

Tags
GridView
Asked by
Scott Waye
Top achievements
Rank 2
Veteran
Iron
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or