我已经覆盖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);