diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1bf474894..2a16810171 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file.
- [Core] Upgrade AD mods with mismatched version in filename (#3287 by: HebaruSan; reviewed: DasSkelett)
- [Multiple] Modpack usability fixes (#3243 by: HebaruSan; reviewed: DasSkelett)
- [Multiple] Fix crashes in audit recommendations (#3292 by: HebaruSan; reviewed: DasSkelett)
+- [GUI] Fix checkbox sorting (#3297 by: HebaruSan; reviewed: DasSkelett)
### Internal
diff --git a/GUI/Controls/ManageMods.cs b/GUI/Controls/ManageMods.cs
index 4c256aca94..76eb2492a1 100644
--- a/GUI/Controls/ManageMods.cs
+++ b/GUI/Controls/ManageMods.cs
@@ -1246,6 +1246,15 @@ private int CompareRows(DataGridViewRow a, DataGridViewRow b)
return CompareColumn(a, b, ModName);
}
+ ///
+ /// Compare two rows based on one of their columns
+ ///
+ /// First row
+ /// Second row
+ /// The column to compare
+ ///
+ /// -1 if a<b, 1 if a>b, 0 if a==b
+ ///
private int CompareColumn(DataGridViewRow a, DataGridViewRow b, DataGridViewColumn col)
{
GUIMod gmodA = a.Tag as GUIMod;
@@ -1256,15 +1265,21 @@ private int CompareColumn(DataGridViewRow a, DataGridViewRow b, DataGridViewColu
var cellB = b.Cells[col.Index];
if (col is DataGridViewCheckBoxColumn cbcol)
{
+ // Checked < non-"-" text < unchecked < "-" text
if (cellA is DataGridViewCheckBoxCell checkboxA)
{
return cellB is DataGridViewCheckBoxCell checkboxB
- ? -((bool)checkboxA.Value).CompareTo((bool)checkboxB.Value)
- : -1;
+ ? -((bool)checkboxA.Value).CompareTo((bool)checkboxB.Value)
+ : (bool)checkboxA.Value || ((string)cellB.Value == "-") ? -1
+ : 1;
}
else
{
- return cellB is DataGridViewCheckBoxCell ? 1: 0;
+ return cellB is DataGridViewCheckBoxCell ? -CompareColumn(b, a, col)
+ : (string)cellA.Value == (string)cellB.Value ? 0
+ : (string)cellA.Value == "-" ? 1
+ : (string)cellB.Value == "-" ? -1
+ : ((string)cellA.Value).CompareTo((string)cellB.Value);
}
}
else