A strange problem involving BeginEdit,EndEdit

Nov 24, 2011 at 12:32 PM

(Still using Catel 1.4 for this project)

I have a datagrid with CheckBoxes as first column.

I have an ObservableCollection called Orders , containing instances of a class PendingOrder. PendingOrders have a boolean attribute called SELECCIONADA , so that each check box is bound to this attribute in this way:

IsChecked

="{Binding SELECCIONADA,Mode=TwoWay,Converter={StaticResource BConverter},UpdateSourceTrigger =PropertyChanged}"

This bounding seems to work properly, except for the following:

Very often... because of the checking/unchecking operations a got the following exception:

 InvalidOperationException:

BeginEdit cannot be invoked twice. A call to BeginEdit must always be closed with a call to CancelEdit or EndEdit.

I got this error even having disconnected the Orders collection from the model...

I appreciate your help hoping I gave you all the information you need. Otherwise please let me know ASAP.

Thank you very much for your support.

 

 
Coordinator
Nov 24, 2011 at 12:35 PM

BeginEdit and CancelEdit are only called on objects implementing the IEditableObject interface and that are decorated with a Model Attribute. If you are not using Model attributes that are changes, then it is probably the grid causing the issues.

The ViewModelBase itself also implements the IEditableObject, and it probably calls that for every row change (which is bad, but ok). So, try to disable the IEditableObject support of the grid in that case.

Nov 24, 2011 at 1:05 PM

Geert:

A few seconds after my post, I confirmed that (as you said) the problem comes from the DataGrid itself.

When you check/uncheck and force a change, sometimes BeginEdit/EndEdit gets an unbalanced number of calls... I think I fixed the problem already.

Thank you very much for your time...

Best regards