title: Why does one of MY WPF DataGrids give the "'EditItem' is not allowed for this view" exception?
body: <p>I have read all the Q&amp;A I could find here and on the MS forums about this exception, and tried most of the suggestions that I understood, and a few others. It seems that this exception can come up for a wide range of causes.</p>
  
  <p>As with others, I have a WPF DataGrid bound to a collection, which throws this exception when one tries to edit one of the cells. They are set to be write-able, the collection is an ObservableCollection, I've implemented get and set handlers which send notification messages.</p>
  
  <p>The suggestions I haven't tried are the ones involving implementing IList's non-generic interface, because I have no idea what I would do to do that. Also, I have many DataGrids bound to various lists and collections in my app which work, and this one used to work when it was bound to a LINQ collection.</p>
  
  <p>Please help me figure out what I need to do here.</p>
  
  <p>The Data Grid is:</p>
  
  <pre><code>&lt;DataGrid Name="dgIngredients" Margin="567,32,0,44" Width="360" ItemsSource="{Binding}" IsReadOnly="False"
             AutoGenerateColumns="False" HorizontalAlignment="Left" CanUserAddRows="False" CanUserDeleteRows="False"&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Width="63" Header="Percent" Binding="{Binding Preference}" IsReadOnly="False" /&gt;
          &lt;DataGridTextColumn SortDirection="Descending" Width="301" Header="Ingredient" Binding="{Binding Ingredient}" IsReadOnly="True" CanUserSort="True" CanUserReorder="False" /&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The column being edited is the non-read-only one, Preference.</p>
  
  <p>The collection is:</p>
  
  <pre><code>private ObservableCollection&lt;RAM_Ingredient&gt; MemberIngredientPrefs = new ObservableCollection&lt;RAM_Ingredient&gt;();
  </code></pre>
  
  <p>The binding is:</p>
  
  <pre><code>dgIngredients.DataContext = MemberIngredientPrefs.OrderBy("Ingredient",true);
  </code></pre>
  
  <p>RAM_Ingredient is:</p>
  
  <pre><code>public class RAM_Ingredient : INotifyPropertyChanged 
  </code></pre>
  
  <p>etc.</p>
  
  <p>Where RAM_Ingredient.Preference is:</p>
  
  <pre><code>private int _Preference;
  public int Preference
  {
      get
      {
          return _Preference;
      }
      set
      {
          // This is needed to send notification of changes (and to not throw an exception on grid edit!):
          if ((_Preference != value))
          {
              SendPropertyChanging();
              _Preference = value;
              SendPropertyChanged("Preference");
          }
      }
  }
  </code></pre>
  
  <p>The exception is:</p>
  
  <pre><code>System.InvalidOperationException was unhandled
    Message='EditItem' is not allowed for this view.
    Source=PresentationFramework
    StackTrace:
         at System.Windows.Controls.ItemCollection.System.ComponentModel.IEditableCollectionView.EditItem(Object item)
         at System.Windows.Controls.DataGrid.EditRowItem(Object rowItem)
         at System.Windows.Controls.DataGrid.OnExecutedBeginEdit(ExecutedRoutedEventArgs e)
  </code></pre>
  
  <p>etc...</p>