{"record":{"id":"5dd54b7e64382088","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedforview-canceledit","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedForView, \"CancelEdit\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedForView, \"CancelEdit\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs","lineNumber":1117,"sourceCode":"            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CommitEdit\"));\n            }\n        }\n\n        /// <summary>\n        /// Complete the transaction started by <seealso cref=\"IEditableCollectionView.EditItem\"/>.\n        /// The pending changes (if any) to the item are discarded.\n        /// </summary>\n        void    IEditableCollectionView.CancelEdit()\n        {\n            IEditableCollectionView ecv = _collectionView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.CancelEdit();\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CancelEdit\"));\n            }\n        }\n\n        /// <summary>\n        /// Returns true if the view supports the notion of \"pending changes\" on the\n        /// current edit item.  This may vary, depending on the view and the particular\n        /// item.  For example, a view might return true if the current edit item\n        /// implements <seealso cref=\"IEditableObject\"/>, or if the view has special\n        /// knowledge about the item that it can use to support rollback of pending\n        /// changes.\n        /// </summary>\n        bool    IEditableCollectionView.CanCancelEdit\n        {\n            get\n            {\n                IEditableCollectionView ecv = _collectionView as IEditableCollectionView;\n                if (ecv != null)\n                {","sourceCodeStart":1099,"sourceCodeEnd":1135,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs#L1099-L1135","documentation":"ItemCollection.CancelEdit discards pending changes to the current edit item, but requires the active view to implement IEditableCollectionView. If the view does not (CanCancelEdit is false), the method throws InvalidOperationException with MemberNotAllowedForView(\"CancelEdit\").","triggerScenarios":"Calling ItemCollection.CancelEdit() while the underlying view does not implement IEditableCollectionView, e.g. a view over a read-only or plain IList source.","commonSituations":"Writing generic undo/cancel logic around ItemsControl edits without first checking CanCancelEdit; using custom CollectionView implementations that omit edit support.","solutions":["Guard with the CanCancelEdit property before calling CancelEdit","Cast the view to IEditableCollectionView and check CanCancelEdit before use","Use an ItemsSource whose view supports edit transactions (e.g. ObservableCollection via ListCollectionView)"],"exampleFix":"// before\nitems.CancelEdit();\n// after\nif (items.CanCancelEdit) { items.CancelEdit(); }","handlingStrategy":"validation","validationCode":"if (items.CanCancelEdit) items.CancelEdit();","typeGuard":"bool canCancel = items.CollectionView is IEditableCollectionView ecv && ecv.CanCancelEdit;","tryCatchPattern":"try { items.CancelEdit(); } catch (InvalidOperationException ex) { /* no editable view */ }","preventionTips":["Check CanCancelEdit before canceling","Bind to editable sources (ObservableCollection/IBindingList)","Write cancel logic against IEditableCollectionView explicitly"],"tags":["wpf","itemcollection","edit-transaction"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}