{"record":{"id":"fbb0d89a722a18e8","repo":"dotnet/wpf","slug":"throw-new-invalidoperationexception-sr-format-sr-fbb0d8","errorCode":null,"errorMessage":"throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"EditItem\"));","messagePattern":"throw new InvalidOperationException\\(SR\\.Format\\(SR\\.MemberNotAllowedForView, \"EditItem\"\\)\\);","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs","lineNumber":603,"sourceCode":"        #region Transactional editing of an item\n\n        /// <summary>\n        /// Begins an editing transaction on the given item.  The transaction is\n        /// completed by calling either <seealso cref=\"IEditableCollectionView.CommitEdit\"/> or\n        /// <seealso cref=\"IEditableCollectionView.CancelEdit\"/>.  Any changes made to the item during\n        /// the transaction are considered \"pending\", provided that the view supports\n        /// the notion of \"pending changes\" for the given item.\n        /// </summary>\n        void IEditableCollectionView.EditItem(object item)\n        {\n            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.EditItem(item);\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"EditItem\"));\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 committed.\n        /// </summary>\n        void IEditableCollectionView.CommitEdit()\n        {\n            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;\n            if (ecv != null)\n            {\n                ecv.CommitEdit();\n            }\n            else\n            {\n                throw new InvalidOperationException(SR.Format(SR.MemberNotAllowedForView, \"CommitEdit\"));\n            }","sourceCodeStart":585,"sourceCodeEnd":621,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/CollectionViewProxy.cs#L585-L621","documentation":"CollectionViewProxy.EditItem(item) starts an edit transaction on the proxied view via IEditableCollectionView. When the wrapped view does not implement that interface (null `ecv` at CollectionViewProxy.cs:603), the proxy throws InvalidOperationException: editing is not allowed for this view.","triggerScenarios":"Calling EditItem on a CollectionViewProxy whose ProxiedView is not an IEditableCollectionView (e.g. custom views, views over non-editable sources).","commonSituations":"Programmatic cell-edit commits in data grids bound to unsupported collections; data-binding infrastructure invoking EditItem automatically; view code ported between collection types.","solutions":["Check CanEditItem (or cast ProxiedView as IEditableCollectionView) before calling EditItem","Edit the data object directly and raise PropertyChanged instead of using view-level edit transactions","Use a source collection whose view implements IEditableCollectionView"],"exampleFix":"// before\nproxy.EditItem(currentItem);\n// after\nif (proxy.CanEditItem)\n{\n    proxy.EditItem(currentItem);\n}","handlingStrategy":"validation","validationCode":"if (!proxy.CanEditItem) return;\nproxy.EditItem(item);","typeGuard":"bool SupportsEditItem(CollectionViewProxy p) => p?.ProxiedView is IEditableCollectionView;","tryCatchPattern":"try { proxy.EditItem(item); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"EditItem\")) { /* edit object directly instead */ }","preventionTips":["Check CanEditItem before starting edit transactions","Edit the business object and raise PropertyChanged as a fallback","Only use view-level editing with collections whose views implement IEditableCollectionView"],"tags":["wpf","collection-view","invalidoperation","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"}