Previously, I had a class that wrapped an internal System.Collections.Generic.List<Item>
(where Item is a class I created). The wrapper class provided several collection-level properties that provided totals, averages, and other computations on items in the list. I was creating a BindingSource
around this wrapped List<>
and another BindingSource
around my class and was able to get at the Items in the wrapped list through the first BindingSource
and the collection-level properties of the wrapper class using the second.
A simplified example looks like:
public class OldClass()
{
private List<Item> _Items;
public OldClass()
{
_Items = new List<Item>();
}
public List<Item> Items { get { return _Items; } }
// collection-level properties
public float AverageValue { get { return Average() } }
public float TotalValue { get { return Total() } }
// ... other properties like this
}
With the binding sources created in this way:
_itemsBindingSource = new BindingSource(oldClass.Items);
_summaryBindingSource = new BindingSource(oldClass);
Recently, I tried to change this class to be derived from System.Collections.Generic.List<Item>
instead of keeping a wrapped List<>
member. My hope was to get rid of the extra wrapper layer and use only one BindingSource
instead of two. However, now I find that I cannot get at the properties that apply to all items in the list (such as AverageValue
) when I do data binding. Only the properties of list items are available.
Am I forced to go back to using a wrapped List<>
of Item
s? Or is there a way that I can get at both the properties of Item
s stored my new class as well as the properties that apply to the collection itself?