Search code examples
wpfdata-bindingieditablecollectionview

'EditItem' is not allowed for this view - databinding issue


I am trying to do data binding in WPF on a data grid using a custom list. My custom list class contains a private data list of type List<T>. I cannot expose this list, however the indexers are exposed for setting and getting individual items. My custom class looks like this:

public abstract class TestElementList<T> : IEnumerable
        where T : class
{
    protected List<T> Data { get; set; }
    public virtual T Get(int index)
    {
        T item = Data[index];
        return item;
    }

    public virtual void Set(int index, T item)
    {
         Data[index] = item;
    }
...
}

The data is binded but when I try to edit it, I get 'EditItem' is not allowed for this view error. On doing extensive searching over web, I found that I might need to implement IEditableCollectionView interface also. Can anybody please help me to either give pointers on how to implement this interface or any suggest any other better way to do databinding on custom list?


Solution

  • Though I am not fully understanding your requirement, do you think using an ObservableCollection will solve your issue?

    public abstract class TestElementList<T> : ObservableCollection<T>
        where T : class
     {
       public virtual T Get(int index)
       {
         T item = this[index];
         return item;
       }
    
       public virtual void Set(int index, T item)
       {
         this[index] = item;
       }
     ...
    }