如何为 PropertyDescriptor 定义类级别属性以对 BindingList 进行排序?
我已经重写了自定义 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个
BindingList.Sort() 的行为就像List.Sort()
take a look at this
BindingList<T>.Sort() to behave like a List<T>.Sort()