/// <summary> /// Sorts the list based on a <see cref="T:System.ComponentModel.PropertyDescriptor"/> and a <see cref="T:System.ComponentModel.ListSortDirection"/>. /// </summary> /// <param name="property">The <see cref="T:System.ComponentModel.PropertyDescriptor"/> to sort by. /// </param><param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection"/> values. /// </param><exception cref="T:System.NotSupportedException"><see cref="P:System.ComponentModel.IBindingList.SupportsSorting"/> is false. /// </exception> public void ApplySort(PropertyDescriptor property, ListSortDirection direction) { ListSortDescription[] descriptions = new[] { new ListSortDescription(property, direction) }; SortDescriptions = new ListSortDescriptionCollection(descriptions); PageProvider.Sort = property.Name + " " + (direction == ListSortDirection.Ascending ? "Asc" : "Desc"); InnerCache.Reset(); OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0)); }
/// <summary> /// Sorts the data source based on the given <see cref="T:System.ComponentModel.ListSortDescriptionCollection"/>. /// </summary> /// <param name="sorts">The <see cref="T:System.ComponentModel.ListSortDescriptionCollection"/> containing the sorts to apply to the data source. /// </param> public void ApplySort(ListSortDescriptionCollection sorts) { SortDescriptions = sorts; string sort = String.Empty; foreach (ListSortDescription descr in sorts) { sort += descr.PropertyDescriptor.Name + " " + (descr.SortDirection == ListSortDirection.Ascending ? "Asc" : "Desc") + ", "; } sort = sort.Trim().Trim(new[] { ',' }); PageProvider.Sort = sort; InnerCache.Reset(); OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0)); }