/// <summary> /// Apply sorting to the collection /// </summary> /// <param name="sortCollection">The sort collection.</param> public void ApplySort(ListSortDescriptionCollection sortCollection) { // Stop raising of events (preserve current state) var oldRaise = this.RaiseListChangedEvents; this.RaiseListChangedEvents = false; try { // sort the items into a temporary list by using the new sort descriptions var tmp = new PropertyComparerCollection <T>(sortCollection); var items = new List <T>(this); items.Sort(tmp); // apply the sorting to the actual list of items var index = 0; foreach (var item in items) { this.SetItem(index++, item); } // and keep the sort descriptions this.sorts = tmp; } finally { // allow events and force the update of bindings this.RaiseListChangedEvents = oldRaise; this.ResetBindings(); } }
/// <summary> /// Entfernt jede mit /// <see /// cref="M:System.ComponentModel.BindingList`1.ApplySortCore(System.ComponentModel.PropertyDescriptor,System.ComponentModel.ListSortDirection)" /> /// angewendete Sortierung, wenn die Sortierung in einer abgeleiteten Klasse implementiert wird; andernfalls wird /// <see cref="T:System.NotSupportedException" /> ausgelöst. /// </summary> /// <exception cref="T:System.NotSupportedException"> /// Die Methode wird in einer abgeleiteten Klasse nicht überschrieben. /// </exception> protected override void RemoveSortCore() { this.sorts = null; }