2

我已经覆盖ApplySortCore了自定义 BindingList 的方法,如下所示:

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

如何定义一个类级别的 PropertyDescriptor(类属性是 InstanceName)来直接调用它,如下所示:

_filteredEntityTally.ApplySort( ???? ,ListSortDirection.Ascending);
4

1 回答 1

2

看看这个

BindingList<T>.Sort() 表现得像 List<T>.Sort()

于 2011-02-08T05:08:11.847 回答