locked
Automatic refresh Items in WPF DataGrid after celle eidt? RRS feed

  • Question

  • Hi  

    I have a WPF Datagrid where i want the itemsource to make a refresh after editing is ended. If the user selects 8 rows and sets one value on ne cell all rows are updated on that cell. That works fine, but when I want to call ….Items.Refresh() in RowEditended then I get an error “unable to refresh during insert or edit….” I’ve tried to make a .. CommitEdit

     () before calling Items.Refresh() but that makes an exception to. How can I refresh my items after editing more than one Row? I can make a button and when I press that button then the items is refreshed just fine, but I would like to make the refresh automatic after editing without having to press any buttons.


    If only I had time to learn everything I wanted ...
    Monday, December 27, 2010 7:20 PM

Answers

  • Hi Jacob,

    This issue is because refresh cannot be made during an edit transaction. And calling CommitEdit in RowEditEnding event won't help because CommitEdit will raise another RowEditEnding event.

    You can use Dispatcher.BeginInvoke method to execute the refresh in delay to resolve this issue.

    Here is a simple sample.

    MyDataGrid.Dispatcher.BeginInvoke(new Action(() => MyDataGrid.Items.Refresh()), System.Windows.Threading.DispatcherPriority.Background);
    

    Hope this helps.

    If you still have any doubts or concerns about this issue, please feel free to let me know.


    Best regards,
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jacob Saugmann Tuesday, December 28, 2010 10:53 AM
    Tuesday, December 28, 2010 3:01 AM

All replies

  • Hi Jacob,

    This issue is because refresh cannot be made during an edit transaction. And calling CommitEdit in RowEditEnding event won't help because CommitEdit will raise another RowEditEnding event.

    You can use Dispatcher.BeginInvoke method to execute the refresh in delay to resolve this issue.

    Here is a simple sample.

    MyDataGrid.Dispatcher.BeginInvoke(new Action(() => MyDataGrid.Items.Refresh()), System.Windows.Threading.DispatcherPriority.Background);
    

    Hope this helps.

    If you still have any doubts or concerns about this issue, please feel free to let me know.


    Best regards,
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jacob Saugmann Tuesday, December 28, 2010 10:53 AM
    Tuesday, December 28, 2010 3:01 AM
  • Hi Min Zhu

     

    THANKS, it solved my problem.

     

    Have a nice day :-)


    If only I had time to learn everything I wanted ...
    Tuesday, December 28, 2010 10:54 AM