【问题标题】:How to define a class level property to a PropertyDescriptor for sorting a BindingList?如何为 PropertyDescriptor 定义类级别属性以对 BindingList 进行排序?
【发布时间】:2011-06-23 04:28:48
【问题描述】:

我已经为自定义 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);

【问题讨论】:

  • 直接你的意思是你想创建一个扩展方法还是什么??
  • @Shekhar_Pro - 我只想在 BindingList 上应用排序。我需要传递一个 PropertyDescriptor 来定义要排序的属性..

标签: c# overriding bindinglist


【解决方案1】:
猜你喜欢
  • 2017-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多