Skip to content

Commit

Permalink
Merge #3297 Fix checkbox sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 22, 2021
2 parents 18c3bda + 2ec5366 commit b748670
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,15 @@ private int CompareRows(DataGridViewRow a, DataGridViewRow b)
return CompareColumn(a, b, ModName);
}

/// <summary>
/// Compare two rows based on one of their columns
/// </summary>
/// <param name="a">First row</param>
/// <param name="b">Second row</param>
/// <param name="col">The column to compare</param>
/// <returns>
/// -1 if a&lt;b, 1 if a&gt;b, 0 if a==b
/// </returns>
private int CompareColumn(DataGridViewRow a, DataGridViewRow b, DataGridViewColumn col)
{
GUIMod gmodA = a.Tag as GUIMod;
Expand All @@ -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
Expand Down

0 comments on commit b748670

Please sign in to comment.