How to define a class level property to a PropertyDescriptor for sorting a BindingList?

2.1k Views Asked by At

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);
1

There are 1 best solutions below

0
On BEST ANSWER