Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. protected virtual void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
  2. {
  3. this.SortProperty = property;
  4. this.SortDirection = direction;
  5. if (direction == ListSortDirection.Ascending)
  6. {
  7. ResetItems(this.OrderBy(item => property.GetValue(item)).ToList());
  8. IsSorted = true;
  9. OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, property));
  10. }
  11. else if (direction == ListSortDirection.Descending)
  12. {
  13. ResetItems(this.OrderByDescending(item => property.GetValue(item)).ToList());
  14. IsSorted = true;
  15. OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, property));
  16. }
  17. }
  18.  
  19. private void ResetItems(List<TItem> items)
  20. {
  21. base.ClearItems();
  22.  
  23. foreach (var item in items)
  24. {
  25. base.InsertItem(IndexOf(item), item);
  26. }
  27. }
  28.  
  29. protected virtual void ApplySortCore(PropertyDescriptor property, ListSortDirection direction)
  30. {
  31. this.SortProperty = property;
  32. this.SortDirection = direction;
  33.  
  34. IEnumerable<T> items = null;
  35. if (direction == ListSortDirection.Ascending)
  36. {
  37. items = this.OrderBy(item => property.GetValue(item));
  38. }
  39. else
  40. {
  41. items = this.OrderByDescending(item => property.GetValue(item));
  42. }
  43.  
  44. ResetItems(items.ToList ());
  45.  
  46. IsSorted = true;
  47. OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, property));
  48. }
  49.  
  50. private void ResetItems(IEnumerbale<TItem> items)
  51. {
  52. base.ClearItems();
  53.  
  54. foreach (var item in items)
  55. {
  56. base.Add(item);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement