views:

298

answers:

1

Hi, I am trying to do data binding in WPF on data grid using a cutom list. My custom list class contains a private data list of type List. I can not expose this list however the indexers are exposed for seeting 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.

Thanks in advance.

A: 

though I am not fully understand 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;
   }
 ...
}
Jobi Joy
Hi, I tried this. But when I do so my inputList is not populated.// code to populate inputlist in main file{ private InputList inputList; InputElement element = new InputElement(); inputList.Add(element);}// Code in TestInputList to add itempublic virtual void Add(T item) { Data.Add(item); }
Scooby
yes this solves it though instead of ObservableCollection, I implemented Ilist and Ilist<T> interfaces for my class and use object of this class for data binding. I am giving the object of this class as data source and set the path to specific properties in this class. hope this helps others who are facing the same issue.
Scooby