I have overridden the ApplySortCore
method for a custom BindingList like so:
public void ApplySort(PropertyDescriptor prop, ListSortDirection direction)
{
ApplySortCore(prop, direction);
}
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
{
sortedList = new System.Collections.ArrayList();
Type interfaceType = prop.PropertyType.GetInterface("IComparable");
if (interfaceType != null)
{
sortPropertyValue = prop;
sortDirectionValue = direction;
unsortedList = new System.Collections.ArrayList(this.Count);
foreach (Object item in this.Items)
{
sortedList.Add(prop.GetValue(item));
unsortedList.Add(item);
}
sortedList.Sort();
isSortedValue = true;
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
}
}
How can I define a class level PropertyDescriptor (the class property is InstanceName) to call this directly like so:
_filteredEntityTally.ApplySort( ???? ,ListSortDirection.Ascending);
take a look at this
BindingList<T>.Sort() to behave like a List<T>.Sort()