{"record":{"id":"b02cf787f1d3c42d","repo":"dotnet/wpf","slug":"sr-format-sr-membernotallowedforview-edititem","errorCode":null,"errorMessage":"SR.Format(SR.MemberNotAllowedForView, \"EditItem\")","messagePattern":"SR\\.Format\\(SR\\.MemberNotAllowedForView, \"EditItem\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs","lineNumber":1083,"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 = _collectionView 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 = _collectionView 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":1065,"sourceCodeEnd":1101,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/ItemCollection.cs#L1065-L1101","documentation":"ItemCollection.EditItem throws InvalidOperationException(SR.MemberNotAllowedForView, \"EditItem\") when the underlying view does not implement IEditableCollectionView, so transactional editing of an item is unavailable. The wrapper forwards only to editing-capable views.","triggerScenarios":"Calling items.EditItem(item) when ItemsSource's view is not an IEditableCollectionView.","commonSituations":"Editable DataGrid scenarios where the ItemsSource is a plain collection without an editable view; rebinding ItemsSource to a type whose default view lacks IEditableCollectionView while editing logic still runs.","solutions":["Bind ItemsSource to a collection whose default view implements IEditableCollectionView.","Guard with `items.CanEditItem` (or check the view) before starting an edit transaction.","Mutate the item's properties directly and rely on INotifyPropertyChanged instead of view-based edit transactions."],"exampleFix":"// before\nitems.EditItem(selectedItem);\n// after\nif (items.CanEditItem)\n    items.EditItem(selectedItem);\nelse\n    throw new InvalidOperationException(\"View does not support EditItem\");","handlingStrategy":"validation","validationCode":"if (items.CanEditItem)\n    items.EditItem(item);","typeGuard":"static bool CanEdit(ItemCollection c) => c.CollectionView is IEditableCollectionView;","tryCatchPattern":"try { items.EditItem(item); }\ncatch (InvalidOperationException) { /* edit transactions unsupported; mutate item directly */ }","preventionTips":["Check CanEditItem before EditItem","Ensure the ItemsSource view implements IEditableCollectionView in editable grids (DataGrid)","Complete or cancel any open edit transaction before rebinding ItemsSource"],"tags":["wpf","itemcollection","invalidoperationexception","edititem"],"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"}