我已经覆盖了自定义 BindingList 的 ApplySortCore
方法,如下所示:
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);
最佳答案
关于c# - 如何为 PropertyDescriptor 定义类级属性以对 BindingList 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4929200/