datagrid and roweditending

Mar 11, 2009 at 9:16 PM
The below is my row edit ending function and the call to refresh the items in my grid after the edit.
When I use the dispatcher to call the refresh function, the error I see is:  'Refresh' is not allowed during an AddNew or EditItem transaction.

However if I refresh the grid manually as in user based, it refreshes fine.
How do you refresh the data after a rowedit?


    private object fillPRSList(object item)
        {

            //LastCat = (string)category;
               prss = sdc.GetScheduleByCategory(LastCat);
            prsl.Clear();
            foreach (ProductReplacementSchedule prs1 in prss)
            {
                prsl.Add(prs1);
            }


            //prs = new ProductReplacementSchedule();
            //prs.PrsID = 0;
            //prsl.Add(prs);
            if (dataGrid1.ItemsSource == null)
                dataGrid1.ItemsSource = prsl;

            dataGrid1.Items.Refresh();
            
            return null;
        }
        

        private void dataGrid1_RowEditEnding(object sender, Microsoft.Windows.Controls.DataGridRowEditEndingEventArgs e)
        {
            DataGridRow dr;
            if (e.EditAction == Microsoft.Windows.Controls.DataGridEditAction.Commit)
            {
                dr = e.Row;
                prs = (ProductReplacementSchedule)dr.Item;
                if (prs.ChangedMachineName == null)
                {
                    prs.ChangedMachineName = "server";
                }
                if (prs.ChangedType == null)
                    prs.ChangedType = "I";
                if (prs.ChangedDate == null)
                    prs.ChangedDate = DateTime.Now;

                if (prs.PrsID == 0)
                    sdc.SaveChange(prs, "add");
                else
                    sdc.SaveChange(prs, "update");
            //    Dispatcher.Invoke(new DispatcherOperationCallback(fillPRSList), DispatcherPriority.ApplicationIdle, dataGrid1);
                
//                fillPRSList(LastCat);
            }
        }
Coordinator
Mar 11, 2009 at 9:54 PM
Dispatcher.Invoke is a sync operation. Hence it executes before RowEditEnding returns and hence the problem. Try using Dispatcher.BeginInvoke instead (which is a async operation).
Dec 1, 2009 at 11:30 AM
Edited Dec 14, 2009 at 12:28 AM

________________