private IOrderedEnumerable <TEntity> ApplySorting(IEnumerable <TEntity> listWithMofifiersApplied) { var sortByFirstCriterion = SortModifiers.First(); IOrderedEnumerable <TEntity> sortedList; if (sortByFirstCriterion.Asc) { sortedList = listWithMofifiersApplied.OrderBy(sortByFirstCriterion.SortByExpression); } else { sortedList = listWithMofifiersApplied.OrderByDescending(sortByFirstCriterion.SortByExpression); } var sortByAddtionalCriteria = SortModifiers.Skip(1); // Sort by more than one column => loop trough all the rest columns foreach (var sortMod in sortByAddtionalCriteria) { if (sortMod.Asc) { sortedList = sortedList.ThenBy(sortMod.SortByExpression); } else { sortedList = sortedList.ThenByDescending(sortMod.SortByExpression); } } return(sortedList); }
public ListViewColumnSorter(int newCol, SortOrder newOrder) { ColumnToSort = newCol; OrderOfSort = newOrder; switch (ColumnToSort) { case 1: mySortModifier = SortModifiers.SortByDate; break; case 5: case 6: mySortModifier = SortModifiers.SortByDecimal; break; default: mySortModifier = SortModifiers.SortByText; break; } ObjectCompare = new NumberCaseInsensitiveComparer(); FirstObjectCompare = new ImageTextComparer(); FirstObjectCompare2 = new CheckboxTextComparer(); }
/// <summary> /// Class constructor. Initializes various elements /// </summary> public ListViewColumnSorter() { // Initialize the column to '0' SortColumn = 0; SortModifier = SortModifiers.SortByText; // Initialize the CaseInsensitiveComparer object objectCompare = new NumberCaseInsensitiveComparer(); firstObjectCompare = new ImageTextComparer(); firstObjectCompare2 = new CheckboxTextComparer(); }