using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace IReaper{
public class SortableBindingList<T>:BindingList<T>
{
ListSortDirection m_SortDirection = ListSortDirection.Ascending;
PropertyDescriptor m_SortProperty = null;
static ListChangedEventArgs resetChangedEvent = new ListChangedEventArgs(ListChangedType.Reset, -1);
bool m_Sorted = false;
protected override bool SupportsSortingCore
{
get
{
return true;
}
}
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
{
this.m_SortProperty = prop;
this.m_SortDirection = direction;
List<T> list = this.Items as List<T>;
if (list == null)
{ return; }
SortCompare<T> compare = new SortCompare<T>(prop, direction);
list.Sort(compare);
this.m_Sorted = true;
OnListChanged(resetChangedEvent);
}
/// <summary>
///
/// </summary>
protected override bool IsSortedCore
{
get
{
return true;
}
}
/// <summary>
///
/// </summary>
protected override ListSortDirection SortDirectionCore
{
get
{
return this.m_SortDirection;
}
}
/// <summary>
///
/// </summary>
protected override PropertyDescriptor SortPropertyCore
{
get
{
return this.m_SortProperty;
}
}
}
}
|