views:

62

answers:

3

I'm using a DataForm in Silverlight 4. Several DataForms, actually, and they share a common RIA Services context. Here's the problem I'm having...

If I start editing a DataField in one of the DataForms, then click on a button that calls Context.SubmitChanges(), I get the following error:

�Entity 'foo' is currently being edited and has uncommitted changes. A call to BeginEdit must be followed by a call to EndEdit or CancelEdit before changes can be submitted.�

Note that the "Submit Changes" button is external to the DataForms and applies to the RIA Services context that is shared between the DataForms (which are each in separate tabs of a tab control).

I'd like to be able to avoid this problem by detecting, in code, when a DataForm is in editing mode. When I'm in debug mode, I can see that the DataForm has properties such as "IsEditing" and "CanCancelEdit" that indicate that it is in editing mode, but these properties do not seem to be available for use in my code.

Any ideas?

A: 

I'm not sure what IsEditing and CanCancelEdit are, they aren't documented.

However there is a Mode property that is DataFormMode enumeration, ReadOnly, Edit and AddNew. There is also an IsItemChanged property which indicates if any actual changes have been made editing began.

AnthonyWJones
Thanks for answering. I tried both of these properties, but they don't give me quite what I need. If you have started making changes to a field but have not made any previous changes, IsItemChanged still reports "false". On the other hand, if you move to a new record but have not started making any changes to it, Mode reports "Edit".
MylesRip
A: 

Since none of the available properties provided the information I needed, I ended up creating my own private field (in the UserControl that contains the DataForm) called _isEditing which is initialized to "false". In the DataForm.BeginningEdit event handler I set it to "true" and in the DataForm.EditEnded event handler I set it to "false". I then created a read-only public property called IsEditing to make the value available externally.

MylesRip
A: 

You can call DataForm.CommitEdit() before calling DomainContext.SubmitChanges() and avoid the error entirely.

Kyle McClellan
True, but I had been considering giving the user the option of whether to commit or cancel the changes.
MylesRip
I'd imagine that's not an option you give them regularly. Typically things get committed when focus changes and I'd wager they'd hate you if you prompted them every time focus left one of the form fields. I'm pretty sure that in this case the focus change just hasn't been processed yet.
Kyle McClellan