Datagrid not in editMode after CommitEdit

Jun 14, 2011 at 3:14 PM

Hello,

I have a datagrid (dg) and an "UNDO"-button. If the user presses UNDO I want the datagrid to refresh.

This works fine, as long as I don't have errors in the datagrid:

        private void dgUNDO_EXECUTE(object sender, ExecutedRoutedEventArgs e)
        {
            _vAdapter.RejectChanges();
            dg.Items.Refresh();
        }

If I have an error, the datagridRow is still in EditMode and it is impossible to refresh.
So I change the code into:
       private void dgUNDO_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            BindingListCollectionView lv = CollectionViewSource.GetDefaultView(dg.ItemsSource) as BindingListCollectionView;
            CT_V_AAND rec;

            if (lv != null)
            {
                if (lv.IsEditingItem)
                {
                    rec = lv.CurrentEditItem as CT_V_AAND;
                    lv.CommitEdit();
                }
            }
            _vAdapter.RejectChanges();
            // Remove errors on record, bij validating again
            rec.MyValidate()
            
            dg.Items.Refresh();
       }

After this, everything looks fine, but I cannot get the datagrid into editMode again. Don't know why this is.

Can somebody help me?
Thanks in advance