Click here to Skip to main content
15,913,587 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a combobBox and a datagrid (dgVadl) that is bound to the selectedItem in the combobox. I also have an UNDO-button to restore the last values in the datagrid.
In the UNDO-button I have:
C#
_Adapter.RejectChanges();
 dgVadl.Items.Refresh();

This works fine if de datagrid contains no errors. If it does contain errors the grid is in edit-mode and then you get the exception: " 'Refresh' is not allowed during an AddNew or EditItem transaction". So I change my code into:
C#
if (view.CanCancelEdit)
     view.CancelEdit();
 else
     view.CommitEdit();
 _Adapter.RejectChanges();
 dgVadl.Items.Refresh();


(BTW: view.canCancelEdit is always false)
The problem now is that de datagrid is no longer in editMode.
To get it in edit-mode again I first have to select an other value in de combobox and then go back again to the first selected item.
Is there another way to get back to editting again?

Thans in advance
Posted
Updated 19-Jun-11 2:51am
v2

Try to remove the row editing event handler and do undo operation and Then add the event handler back.I have not tried out the code.Just an assumption that it may work.This thread below may give you some idea.

http://social.msdn.microsoft.com/Forums/en/wpf/thread/8898cacc-d72e-4be6-9045-ea5206c1ebb2[^]
 
Share this answer
 
Thanks for your answer, but that is not a solution. The "RowEditEnding" never fires in this case.

The problem was that datagrid.HasRowValidation (or datagrid.HasCellValidation depending on my validationhandling) the value 'true' kept. Even after the refresh(), when no more errors existed.
The "OnCanExecuteBeginEdit()" checks for this value and returns: canExecute = false;

I do not know how to solve this.
I now use the Microsoft datagrid and the error no longer exists, so I guess it is a bug.

Thanks anyway,
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900