dotnet/wpf · error · ArgumentException

SR.CannotEditPlaceholder

Error message

SR.CannotEditPlaceholder

What it means

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.

Solutions

  1. Compare the item to CollectionView.NewItemPlaceholder and skip/refuse editing before calling EditItem.
  2. In grid edit handlers, check the row's item type or the placeholder marker before opening edit UI.
  3. Redirect placeholder-row activation to your AddNew flow instead of EditItem.
  4. Hide or style the placeholder row as read-only if editing it should never be possible.

Example fix

// before
view.EditItem(dataGrid.SelectedItem);

// after
var item = dataGrid.SelectedItem;
if (!Equals(item, CollectionView.NewItemPlaceholder))
    view.EditItem(item);
Defensive patterns

Strategy: type-guard

Validate before calling

// C#
if (!Equals(item, CollectionView.NewItemPlaceholder))
    view.EditItem(item);

Type guard

bool IsEditableItem(object item) => !Equals(item, CollectionView.NewItemPlaceholder);

Try / catch

try { view.EditItem(item); }
catch (ArgumentException ex) { Log.Warn("Tried to edit placeholder", ex); }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/b4109cb1ecf163d0. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingListCollectionView.cs:955

        }

        #endregion Removing items

        #region Transactional editing of an item

        /// <summary>
        /// Begins an editing transaction on the given item.  The transaction is
        /// completed by calling either <seealso cref="CommitEdit"/> or
        /// <seealso cref="CancelEdit"/>.  Any changes made to the item during
        /// the transaction are considered "pending", provided that the view supports
        /// the notion of "pending changes" for the given item.
        /// </summary>
        public void EditItem(object item)
        {
            VerifyRefreshNotDeferred();

            if (item == NewItemPlaceholder)
                throw new ArgumentException(SR.CannotEditPlaceholder, nameof(item));

            if (IsAddingNew)
            {
                if (System.Windows.Controls.ItemsControl.EqualsEx(item, _newItem))
                    return;     // EditItem(newItem) is a no-op

                CommitNew();    // implicitly close a previous AddNew
            }

            CommitEdit();   // implicitly close a previous EditItem transaction

            SetEditItem(item);

            IEditableObject ieo = item as IEditableObject;
            ieo?.BeginEdit();
        }

        /// <summary>

View on GitHub (pinned to 81131a70a4)