none
'DeferRefresh' is not allowed during an AddNew or EditItem transaction.

    Question

  • Hi,

     

    I have this exception when using my application. I know more or less where it comes from :

    My application uses tabs. I open a tab containing a datagrid. When i double click on a cell, it automatically creates a new object (in the collection binded). However, lets say my cell is still in editing mode. If i open a new tab, and then want to go back in the previous one, I get this error message.

    To avoid this problem, I would like my cell to stop editing mode anytime i click somewhere else.

    Thanks by advance for your help.

     

    Toast.

    Thursday, May 27, 2010 8:13 AM

All replies

  • Any idea / solution ?
    Thursday, May 27, 2010 12:33 PM
  • Hi Toast,

    What is the error message, could you share it? Is it "'DeferRefresh' is not allowed during an AddNew or EditItem transaction"? And it seems a issue of WPF Toolkit DataGrid, Please refer to this link: http://wpf.codeplex.com/WorkItem/View.aspx?WorkItemId=7830 So could you please try to use the latest version of WPF Toolkit or try to code it in the Visua lStudio 2010 with .Net 4(WPF 4 has a DataGrid control)

    However, it is hard to find the cause without any code, could you please share some code about your application?

    Sincerely, 

    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, May 31, 2010 9:05 AM
    Moderator
  • Hi Toast2,

    For your information, I fully documented a similar case in

    https://connect.microsoft.com/VisualStudio/feedback/details/532494/wpf-datagrid-and-tabcontrol-deferrefresh-exception

    and

    https://connect.microsoft.com/VisualStudio/feedback/details/551128/wpf-datagrid-and-tabcontrol-deferrefresh-exception#

    When you click on " Bug 551128 : Details/Expand", you can download a documented zip file with all material I could produce for the defer Refresh exception.

    If this case matches yours, you can add a vote for 551128 and 532494 (top left)

    If your scenario is (even slightly) different, feel free to add your own zip file to 551128 or to open your own DeferRefresh bug entry. This can always help the development/maintenance teams.

    Kind regards, Chris.

     

     

     

    Monday, May 31, 2010 3:26 PM
  • Hi, I built a workaround for this, which is documented in thread

     

    http://social.msdn.microsoft.com/Forums/en/wpf/thread/187b2b8f-d403-4bf3-97ad-7f93b4385cdf

     

    It basically gets the datagrid out of edit mode (canceling the pending changes) when it loses focus or changes its DataContext. I don't report the whole solution also in this thread, because it is a bit long, so please visit that link.

     

    Cheers,

    Emanuele

    Wednesday, September 22, 2010 7:12 AM
  • https://connect.microsoft.com/VisualStudio/feedback/details/532494/wpf-datagrid-and-tabcontrol-deferrefresh-exception

    documents the limit of the proposed workaround : the model class must implement 'IEditableObject'

    • Edited by Rhodos Saturday, October 09, 2010 8:59 AM updating answer completeness
    Friday, October 08, 2010 12:28 PM
  • I have the same problem. WPF, Tabs, using IEditableObject but I'm not using DataGrids.

     

    Can I safely catch and ignore this exception or will that open up a can of worms?

    Tuesday, June 07, 2011 2:05 PM
  • Hi IngoVals,

    If at all possible, you could upload a file attachment with your (simplified) Solution/Project in

    https://connect.microsoft.com/VisualStudio/feedback/details/532494/wpf-datagrid-and-tabcontrol-deferrefresh-exception#details (or open an additional connect report)

    Your case is quite interesting since you are declaring IEditableObject on your class, a feature that precisely should help avoiding the problem, not cause it.

    Thanks, Rhodos

    Wednesday, June 08, 2011 1:10 PM
  • Try following sequence before calling Refersh on CollectionView or <DataGrid>.Items

    <DataGrid>.CommitEdit();

    <DataGrid>.CancelEdit();

    Worked for me.

    Tuesday, November 08, 2011 12:25 PM
  • Thanks for Me 2
    Thursday, October 18, 2012 4:31 AM
  • Basically I have a tab control in the GUI and there is WPF 4.0 datagrid in one of the tabs. When I click on a cell in the grid and edit something and then switch tabs I was getting Defer Refresh error (DeferRefresh' is not allowed during an AddNew or EditItem transaction.).

    So I call datagrid.CancelEdit(DataGridEditingUnit.Row) when tab is switched to cancel any pending edit and Defer refresh issue is gone.

    But what I really want to do is CommitEdit() so that the user doesn't have to reenter the data again. And datagrid.CommitEdit(DataGridEditingUnit.Row, true) doesn't work for me.

    I get the below error on CommitEnd(): "Cannot perform this operation while dispatcher processing is suspended".

    Any help is appreciated.

    PS: I have tried datagrid.CommitEdit() and datagrid.CommitEdit(DataGridEditingUnit.Column, true) and it didnt work.

    Thanks guys.


    • Edited by Nikhil Kesar Friday, August 16, 2013 8:32 PM typo
    Friday, August 16, 2013 8:31 PM