diff --git a/GUI/Main.cs b/GUI/Main.cs
index f0684d6eaa..5b637bb46c 100644
--- a/GUI/Main.cs
+++ b/GUI/Main.cs
@@ -564,7 +564,7 @@ private void MarkAllUpdatesToolButton_Click(object sender, EventArgs e)
if (Main.Instance.configuration.AutoSortByUpdate)
{
// set new sort column
- var new_sort_column = ModList.Columns[1];
+ var new_sort_column = ModList.Columns[UpdateCol.Index];
var current_sort_column = ModList.Columns[configuration.SortByColumnIndex];
// Reset the glyph.
@@ -573,7 +573,7 @@ private void MarkAllUpdatesToolButton_Click(object sender, EventArgs e)
UpdateFilters(this);
// Select the top row and scroll the list to it.
- ModList.CurrentCell = ModList.Rows[0].Cells[1];
+ ModList.CurrentCell = ModList.Rows[0].Cells[SelectableColumnIndex()];
}
ModList.Refresh();
@@ -1052,9 +1052,7 @@ private void FocusMod(string key, bool exactMatch, bool showAsFirst = false)
{
match.Selected = true;
- // Setting this to the 'Name' cell prevents the checkbox from being toggled
- // by pressing 'Space' while the row is not indicated as active.
- ModList.CurrentCell = match.Cells[2];
+ ModList.CurrentCell = match.Cells[SelectableColumnIndex()];
if (showAsFirst)
ModList.FirstDisplayedScrollingRowIndex = match.Index;
}
diff --git a/GUI/MainModList.cs b/GUI/MainModList.cs
index 2e90a74516..3c1b05371c 100644
--- a/GUI/MainModList.cs
+++ b/GUI/MainModList.cs
@@ -418,13 +418,13 @@ private void ModList_KeyDown(object sender, KeyEventArgs e)
{
case Keys.Home:
// First row.
- ModList.CurrentCell = ModList.Rows[0].Cells[2];
+ ModList.CurrentCell = ModList.Rows[0].Cells[SelectableColumnIndex()];
e.Handled = true;
break;
case Keys.End:
// Last row.
- ModList.CurrentCell = ModList.Rows[ModList.Rows.Count - 1].Cells[2];
+ ModList.CurrentCell = ModList.Rows[ModList.Rows.Count - 1].Cells[SelectableColumnIndex()];
e.Handled = true;
break;
@@ -450,6 +450,25 @@ private void ModList_KeyDown(object sender, KeyEventArgs e)
}
}
+ ///
+ /// Find a column of the grid that can contain the CurrentCell.
+ /// Can't be hidden or an exception is thrown.
+ /// Shouldn't be a checkbox because we don't want the space bar to toggle.
+ ///
+ ///
+ /// Index of the column to use.
+ ///
+ private int SelectableColumnIndex()
+ {
+ // First try the currently active cell's column
+ return ModList.CurrentCell?.ColumnIndex
+ // If there's no currently active cell, use the first visible non-checkbox column
+ ?? ModList.Columns.Cast()
+ .FirstOrDefault(c => c is DataGridViewTextBoxColumn && c.Visible)?.Index
+ // Otherwise use the Installed checkbox column since it can't be hidden
+ ?? Installed.Index;
+ }
+
///
/// Called on key press when the mod is focused. Scrolls to the first mod with name
/// beginning with the key pressed. If more than one unique keys are pressed in under