From 5f8ca9a0b528f3bf0d2d5b450beaf4ae67add550 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Mon, 9 Aug 2021 19:07:00 -0600 Subject: [PATCH] Changed sort method. --- LibationWinForms/ProductsGrid.Designer.cs | 4 ++-- LibationWinForms/SortableBindingList2[T].cs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/LibationWinForms/ProductsGrid.Designer.cs b/LibationWinForms/ProductsGrid.Designer.cs index 0a74a123..ce28cfdd 100644 --- a/LibationWinForms/ProductsGrid.Designer.cs +++ b/LibationWinForms/ProductsGrid.Designer.cs @@ -91,7 +91,7 @@ this.gridEntryDataGridView.ReadOnly = true; this.gridEntryDataGridView.RowHeadersVisible = false; this.gridEntryDataGridView.RowTemplate.Height = 82; - this.gridEntryDataGridView.Size = new System.Drawing.Size(1503, 380); + this.gridEntryDataGridView.Size = new System.Drawing.Size(1505, 380); this.gridEntryDataGridView.TabIndex = 0; // // dataGridViewImageButtonBoxColumn1 @@ -216,7 +216,7 @@ this.Controls.Add(this.gridEntryDataGridView); this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "ProductsGrid"; - this.Size = new System.Drawing.Size(1503, 380); + this.Size = new System.Drawing.Size(1505, 380); ((System.ComponentModel.ISupportInitialize)(this.gridEntryBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.gridEntryDataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/LibationWinForms/SortableBindingList2[T].cs b/LibationWinForms/SortableBindingList2[T].cs index 1a0e1d97..0a2bf465 100644 --- a/LibationWinForms/SortableBindingList2[T].cs +++ b/LibationWinForms/SortableBindingList2[T].cs @@ -36,7 +36,11 @@ namespace LibationWinForms Comparer.PropertyName = property.Name; Comparer.Direction = direction; - itemsList.Sort(Comparer); + //Array.Sort and Liat.Sort are unstable sorts. OrderBy is stable. + var sortedItems = itemsList.OrderBy((ge) => ge, Comparer).ToArray(); + + itemsList.Clear(); + itemsList.AddRange(sortedItems); propertyDescriptor = property; listSortDirection = direction;