From 4a82541ffdaa9ffa95e91a93a0b52da2f6ef3296 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Mon, 23 May 2022 17:46:55 -0600 Subject: [PATCH] Fix error while removing filter on a sorted binding list --- Source/LibationWinForms/grid/FilterableSortableBindingList.cs | 4 ++++ Source/LibationWinForms/grid/SortableBindingList1.cs | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/LibationWinForms/grid/FilterableSortableBindingList.cs b/Source/LibationWinForms/grid/FilterableSortableBindingList.cs index e309f7fe..dcb70524 100644 --- a/Source/LibationWinForms/grid/FilterableSortableBindingList.cs +++ b/Source/LibationWinForms/grid/FilterableSortableBindingList.cs @@ -120,6 +120,8 @@ namespace LibationWinForms int visibleCount = Items.Count; + SuspendSorting = true; + foreach (var item in FilterRemoved.ToList()) { if (item.Parent is null || item.Parent.Liberate.Expanded) @@ -129,6 +131,8 @@ namespace LibationWinForms } } + SuspendSorting = false; + if (IsSortedCore) Sort(); else diff --git a/Source/LibationWinForms/grid/SortableBindingList1.cs b/Source/LibationWinForms/grid/SortableBindingList1.cs index 0a0606f5..ec545340 100644 --- a/Source/LibationWinForms/grid/SortableBindingList1.cs +++ b/Source/LibationWinForms/grid/SortableBindingList1.cs @@ -15,6 +15,7 @@ namespace LibationWinForms public SortableBindingList1() : base(new List()) { } public SortableBindingList1(IEnumerable enumeration) : base(new List(enumeration)) { } + protected bool SuspendSorting { get; set; } protected MemberComparer Comparer { get; } = new(); protected override bool SupportsSortingCore => true; protected override bool SupportsSearchingCore => true; @@ -60,7 +61,7 @@ namespace LibationWinForms protected override void OnListChanged(ListChangedEventArgs e) { - if (isSorted && + if (isSorted && !SuspendSorting && ((e.ListChangedType == ListChangedType.ItemChanged && e.PropertyDescriptor == SortPropertyCore) || e.ListChangedType == ListChangedType.ItemAdded)) {