/// <summary> /// Sorts the list using the given comparer. /// </summary> /// <param name="comparer"></param> public void Sort(IComparer comparer, SortDirection direction) { if (comparer == null) { throw new ArgumentNullException("comparer"); } IComparerInitialize init = comparer as IComparerInitialize; if (init != null) { init.StartCompare(this); } try { // wrap? IComparer toUse = comparer; if (direction == SortDirection.Descending) { toUse = new ComparerReverser(comparer); } // sort... this.InnerList.Sort(toUse); } finally { if (init != null) { init.EndCompare(); } } }
/// <summary> /// Sorts the list by the given property. /// </summary> /// <param name="property"></param> /// <param name="direction"></param> public void ApplySort(PropertyDescriptor property, System.ComponentModel.ListSortDirection direction) { // are we trying to sort? if (property == null) { // set... _sortDirection = SortDirection.Ascending; _sortProperty = null; return; } // data... SortDirection useDirection = SortDirection.Ascending; if (direction == ListSortDirection.Descending) { useDirection = SortDirection.Descending; } // get a comparer... IComparer comparer = this.GetComparer(property); if (comparer == null) { throw new ArgumentNullException("comparer"); } // mbr - 2010-04-05 - changed reversal method... //// set... //if(comparer is IComparerDirection) // ((IComparerDirection)comparer).Direction = useDirection; IComparer toUse = comparer; if (useDirection == SortDirection.Descending) { toUse = new ComparerReverser(comparer); } // sort by the given property... this.InnerList.Sort(toUse); // set... _sortProperty = property; if (direction == ListSortDirection.Ascending) { _sortDirection = SortDirection.Ascending; } else { _sortDirection = SortDirection.Descending; } }