static void Main(string[] args) { BindingSourceList <StringValue> total = new BindingSourceList <StringValue> { new StringValue("one"), new StringValue("two"), new StringValue("three"), new StringValue("four"), new StringValue("five"), new StringValue("six") }; Func <StringValue, bool> filter = (t => t.Contains("e")); BindingProxyList <StringValue> Proxy = new BindingProxyList <StringValue>(total, filter, "Value", ListSortDirection.Descending); foreach (StringValue item in Proxy) { Console.WriteLine(item.Value); } }
/// <summary> /// Initializes a new instance of the <see cref="T:ProxyList.BindingProxyList`1"/> class. /// </summary> /// <param name="source">Source.</param> /// <param name="filter">Filter.</param> /// <param name="sortBy">Sort by.</param> /// <param name="sortDirection">Sort direction.</param> public BindingProxyList(BindingSourceList <T> source, Func <T, bool> filter = null, string sortBy = "", ListSortDirection sortDirection = ListSortDirection.Ascending) : base(source) { Source = source; Filter = filter; SortBy = sortBy; SortDirection = sortDirection; PropertyDescriptorCollection = TypeDescriptor.GetProperties(typeof(T)); SortProperty = PropertyDescriptorCollection.Find(sortBy, false); if (SortProperty == null) { SortProperty = PropertyDescriptorCollection.Find(DefaultSortProperty, false); SortBy = DefaultSortProperty; } if (Filter == null) { Filter = (f => true); } source.ListChanged += Source_ListChanged; source.DeletedEvent += Source_DeletedEvent; Source_ListChanged(null, new ListChangedEventArgs(ListChangedType.Reset, -1)); }