2011-02-08 35 views
1

我已經覆蓋了ApplySortCore方法自定義的BindingList像這樣:如何將一個類級屬性定義爲PropertyDescriptor以對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(類屬性爲實例名)直接調用此像這樣:

_filteredEntityTally.ApplySort(???? ,ListSortDirection.Ascending); 
+0

你的意思是你想CREA te擴展方法還是什麼? – 2011-02-08 03:57:18

+0

@Shekhar_Pro - 我只是想在BindingList上應用排序。我需要傳遞一個PropertyDescriptor來定義要排序的屬性.. – wulfgarpro 2011-02-08 04:00:22

回答

相關問題