コード例 #1
0
        private void add_Click(object sender, RoutedEventArgs e)
        {
            IEditableCollectionView editableCollectionView = itemsControl.Items as IEditableCollectionView;

            if (!editableCollectionView.CanAddNew)
            {
                MessageBox.Show("You cannot add items to the list.");
                return;
            }

            // Create a window that prompts the user to enter a new
            // item to sell.
            ChangeItemWindow win = new ChangeItemWindow();

            //Create a new item to be added to the collection.
            win.DataContext = editableCollectionView.AddNew();

            // If the user submits the new item, commit the new
            // object to the collection.  If the user cancels
            // adding the new item, discard the new item.
            if ((bool)win.ShowDialog())
            {
                editableCollectionView.CommitNew();
            }
            else
            {
                editableCollectionView.CancelNew();
            }
        }
コード例 #2
0
        /// <summary>
        /// Ends the add transaction and discards the pending new item.
        /// </summary>
        void IEditableCollectionView.CancelNew()
        {
            IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView;

            if (iEditableCollectionView == null)
            {
                throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "CancelNew"));
            }
            iEditableCollectionView.CancelNew();
        }
コード例 #3
0
        /// <summary>
        /// Porzucenie zmian
        /// </summary>
        private void OnCancel(object sender, RoutedEventArgs e)
        {
            if (m_mode == eDbOperation.Insert)
            {
                m_endpoints.CancelNew();
            }
            else
            {
                m_endpoints.CancelEdit();
            }

            RestoreTabControl();
        }
コード例 #4
0
        /// <summary>
        /// Complete the transaction started by <seealso cref="IEditableCollectionView.AddNew"/>.  The new
        /// item is removed from the collection.
        /// </summary>
        void IEditableCollectionView.CancelNew()
        {
            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;

            if (ecv != null)
            {
                ecv.CancelNew();
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.MemberNotAllowedForView, "CancelNew"));
            }
        }
コード例 #5
0
        public void ICVF_CancelNew()
        {
            EntitySet <City>        entitySet = this.CreateEntitySet <City>();
            IEditableCollectionView view      = this.GetIECV(entitySet);

            City city = (City)view.AddNew();

            Assert.IsTrue(entitySet.Contains(city),
                          "EntitySet should contain the second entity after AddNew.");

            view.CancelNew();
            Assert.IsFalse(entitySet.Contains(city),
                           "EntitySet should no longer contain the second entity after CancelNew.");
        }
コード例 #6
0
        // Token: 0x0600740A RID: 29706 RVA: 0x00212E5C File Offset: 0x0021105C
        void IEditableCollectionView.CancelNew()
        {
            IEditableCollectionView editableCollectionView = this.ProxiedView as IEditableCollectionView;

            if (editableCollectionView != null)
            {
                editableCollectionView.CancelNew();
                return;
            }
            throw new InvalidOperationException(SR.Get("MemberNotAllowedForView", new object[]
            {
                "CancelNew"
            }));
        }
コード例 #7
0
        private static void RollbackOnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!(sender is ItemsControl senderItemsControl))
            {
                return;
            }

            IEditableCollectionView collection = senderItemsControl.Items as IEditableCollectionView;

            if (collection.IsEditingItem)
            {
                collection.CancelEdit();
            }
            else if (collection.IsAddingNew)
            {
                collection.CancelNew();
            }
        }
コード例 #8
0
 public void Dispose()
 {
     if (!isDisposed)
     {
         filterPr.itemsDeferRefreshCount--;
         if (filterPr.itemsDeferRefreshCount <= 0)
         {
             filterPr.itemsDeferRefreshCount = 0;
             IEditableCollectionView cv = filterPr.CollectionView as IEditableCollectionView;
             if (cv != null)
             {
                 if (cv.IsAddingNew)
                 {
                     cv.CancelNew();
                 }
                 if (cv.IsEditingItem)
                 {
                     cv.CancelEdit();
                 }
             }
             if (filterPr.isFilterActive)
             {
                 filterPr.CollectionView.Filter = filterPr.filterFunction;
             }
             else //if (filterVm.items.PropertyFilter==null)
             {
                 filterPr.CollectionView.Filter = null;
             }
             filterPr.RaiseFiltered();
             if (filterPr.itemsDeferRefresh != null)
             {
                 filterPr.itemsDeferRefresh.Dispose();
             }
             filterPr.itemsDeferRefresh = null;
         }
         isDisposed = true;
     }
     else
     {
         throw new ObjectDisposedException("FilterPresenter(" + filterPr.CollectionView.ToString() + ").GetDeferRefresh()");
     }
 }
コード例 #9
0
        static void RollbackDataGridOnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            DataGrid senderDatagrid = sender as DataGrid;

            if (senderDatagrid == null)
            {
                return;
            }

            IEditableCollectionView collection = senderDatagrid.Items as IEditableCollectionView;

            if (collection.IsEditingItem)
            {
                collection.CancelEdit();
            }
            else if (collection.IsAddingNew)
            {
                collection.CancelNew();
            }
        }
コード例 #10
0
        /// <summary>
        /// Cancels the current entity editing and exits the editing mode.
        /// </summary>
        /// <param name="dataItem">The entity being edited</param>
        /// <returns>True if a cancellation operation was invoked.</returns>
        public bool CancelEdit(object dataItem)
        {
#if FEATURE_IEDITABLECOLLECTIONVIEW
            IEditableCollectionView editableCollectionView = this.EditableCollectionView;
            if (editableCollectionView != null)
            {
                _owner.NoCurrentCellChangeCount++;
                this.EndingEdit = true;
                try
                {
                    if (editableCollectionView.IsAddingNew && dataItem == editableCollectionView.CurrentAddItem)
                    {
                        editableCollectionView.CancelNew();
                        return(true);
                    }
                    else if (editableCollectionView.CanCancelEdit)
                    {
                        editableCollectionView.CancelEdit();
                        return(true);
                    }
                }
                finally
                {
                    _owner.NoCurrentCellChangeCount--;
                    this.EndingEdit = false;
                }

                return(false);
            }
#endif

            IEditableObject editableDataItem = dataItem as IEditableObject;
            if (editableDataItem != null)
            {
                editableDataItem.CancelEdit();
                return(true);
            }

            return(true);
        }
コード例 #11
0
ファイル: DataGridHelper.cs プロジェクト: ssjda-ddi/EDO
        public static void Finalize(DataGrid grid)
        {
            if (grid == null)
            {
                return;
            }
            grid.CommitEdit(); // Try to Commit first
            IEditableCollectionView collection = grid.Items as IEditableCollectionView;

            if (collection.IsEditingItem)
            {
                collection.CancelEdit();
            }
            else if (collection.IsAddingNew)
            {
                collection.CancelNew();
                //If Save button clicked while editing, the line for new item is disappered.
                //Hide it temporarily and show it again
                grid.CanUserAddRows = false;
                grid.CanUserAddRows = true;
            }
        }
コード例 #12
0
        static void RollbackDataGridOnLostFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            DataGrid senderDatagrid = sender as DataGrid;

            if (senderDatagrid == null)
            {
                return;
            }

            UIElement focusedElement = Keyboard.FocusedElement as UIElement;

            if (focusedElement == null)
            {
                return;
            }

            DataGrid focusedDatagrid = GetParentDatagrid(focusedElement); //let's see if the new focused element is inside a datagrid

            if (focusedDatagrid == senderDatagrid)
            {
                return;
                //if the new focused element is inside the same datagrid, then we don't need to do anything;
                //this happens, for instance, when we enter in edit-mode: the DataGrid element loses keyboard-focus, which passes to the selected DataGridCell child
            }

            //otherwise, the focus went outside the datagrid; in order to avoid exceptions like ("DeferRefresh' is not allowed during an AddNew or EditItem transaction")
            //or ("CommitNew is not allowed for this view"), we undo the possible pending changes, if any
            IEditableCollectionView collection = senderDatagrid.Items as IEditableCollectionView;

            if (collection.IsEditingItem)
            {
                collection.CancelEdit();
            }
            else if (collection.IsAddingNew)
            {
                collection.CancelNew();
            }
        }
コード例 #13
0
 public void CancelNew()
 {
     _collectionView.CancelNew();
 }