{"record":{"id":"b4109cb1ecf163d0","repo":"dotnet/wpf","slug":"sr-cannoteditplaceholder","errorCode":null,"errorMessage":"SR.CannotEditPlaceholder","messagePattern":"SR\\.CannotEditPlaceholder","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs","lineNumber":955,"sourceCode":"        }\n\n        #endregion Removing items\n\n        #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=\"CommitEdit\"/> or\n        /// <seealso cref=\"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        public void EditItem(object item)\n        {\n            VerifyRefreshNotDeferred();\n\n            if (item == NewItemPlaceholder)\n                throw new ArgumentException(SR.CannotEditPlaceholder, nameof(item));\n\n            if (IsAddingNew)\n            {\n                if (System.Windows.Controls.ItemsControl.EqualsEx(item, _newItem))\n                    return;     // EditItem(newItem) is a no-op\n\n                CommitNew();    // implicitly close a previous AddNew\n            }\n\n            CommitEdit();   // implicitly close a previous EditItem transaction\n\n            SetEditItem(item);\n\n            IEditableObject ieo = item as IEditableObject;\n            ieo?.BeginEdit();\n        }\n\n        /// <summary>","sourceCodeStart":937,"sourceCodeEnd":973,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs#L937-L973","documentation":"EditItem(item) begins an edit transaction on the given item, but throws ArgumentException when the item is CollectionView.NewItemPlaceholder. The placeholder is a virtual row for the 'add new' UI and has no real data to edit, so it cannot be the target of EditItem.","triggerScenarios":"Calling EditItem(CollectionView.NewItemPlaceholder) directly, or passing the currently selected item from a grid whose selection is on the placeholder row (e.g. double-click to edit on the 'new item' row).","commonSituations":"DataGrids with NewItemPlaceholderPosition set and a begin-edit handler that passes e.Item or SelectedItem unconditionally; custom row-edit dialogs opened from the placeholder row.","solutions":["Compare the item to CollectionView.NewItemPlaceholder and skip/refuse editing before calling EditItem.","In grid edit handlers, check the row's item type or the placeholder marker before opening edit UI.","Redirect placeholder-row activation to your AddNew flow instead of EditItem.","Hide or style the placeholder row as read-only if editing it should never be possible."],"exampleFix":"// before\nview.EditItem(dataGrid.SelectedItem);\n\n// after\nvar item = dataGrid.SelectedItem;\nif (!Equals(item, CollectionView.NewItemPlaceholder))\n    view.EditItem(item);","handlingStrategy":"type-guard","validationCode":"// C#\nif (!Equals(item, CollectionView.NewItemPlaceholder))\n    view.EditItem(item);","typeGuard":"bool IsEditableItem(object item) => !Equals(item, CollectionView.NewItemPlaceholder);","tryCatchPattern":"try { view.EditItem(item); }\ncatch (ArgumentException ex) { Log.Warn(\"Tried to edit placeholder\", ex); }","preventionTips":["Guard grid begin-edit handlers against the placeholder row.","Redirect placeholder activation to AddNew flow.","Style the placeholder row as non-editable."],"tags":["wpf","data-binding","placeholder"],"backgroundTag":"invalid-argument-value","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"}