From 2c7e9230ff5461200a959eca8b881d4e8fec3780 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 26 Apr 2023 11:32:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B3=D0=BE=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TransportCompany/SortableBindingList.cs | 103 ------------------ 1 file changed, 103 deletions(-) delete mode 100644 TransportCompany/TransportCompany/SortableBindingList.cs diff --git a/TransportCompany/TransportCompany/SortableBindingList.cs b/TransportCompany/TransportCompany/SortableBindingList.cs deleted file mode 100644 index 30ae163..0000000 --- a/TransportCompany/TransportCompany/SortableBindingList.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace TransportCompany -{ - public class SortableBindingList : BindingList - { - private bool IsSorted { get; set; } - - private ListSortDirection SortDirection { get; set; } - - private PropertyDescriptor SortProperty { get; set; } - - protected override bool SupportsSortingCore - { - get - { - return true; - } - } - - protected override ListSortDirection SortDirectionCore - { - get - { - return SortDirection; - } - } - - protected override PropertyDescriptor SortPropertyCore - { - get - { - return SortProperty; - } - } - - protected override void ApplySortCore(PropertyDescriptor PDsc, ListSortDirection Direction) - { - List items = Items as List; - if (items is null) - { - IsSorted = false; - } - else - { - var PCom = new PCompare(PDsc.Name, Direction); - items.Sort(PCom); - IsSorted = true; - SortDirection = Direction; - SortProperty = PDsc; - } - OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); - } - - protected override bool IsSortedCore - { - get - { - return IsSorted; - } - } - - protected override void RemoveSortCore() - { - IsSorted = false; - } - - #region Constructors - public SortableBindingList(ICollection list) : base((IList)list) - { - } - public SortableBindingList() : base() - { - } - - #endregion - #region Property comparer - private class PCompare : IComparer - { - private PropertyInfo PropInfo { get; set; } - private ListSortDirection SortDir { get; set; } - internal PCompare(string SortProperty, ListSortDirection SortDirection) - { - PropInfo = typeof(T).GetProperty(SortProperty); - SortDir = SortDirection; - } - internal int Compare(T x, T y) - { - return SortDir == ListSortDirection.Ascending ? Comparer.Default.Compare(PropInfo.GetValue(x, null), PropInfo.GetValue(y, null)) : Comparer.Default.Compare(PropInfo.GetValue(y, null), PropInfo.GetValue(x, null)); - } - - int IComparer.Compare(T x, T y) => Compare(x, y); - } - #endregion - } -}