Fix index -1 exception in Manage Instances #3800
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Noticed during dev of #3797 (in relation to the Game column instead), but I think I recall sporadic reports of this without those changes that I couldn't pin down at the time, so it seemed worth splitting into its own fix.
Cause
The list view has two columns that are sometimes visible and sometimes hidden: Game and Hours Played. To hide them, we remove them from the list view. If they become visible again, we insert them using their
Column.Index
property, which unfortunately is-1
for any column not already in the list:Inserting the column with an index of
-1
throws an exception. This happens anytime a previously hidden column is supposed to become visible (including adding a KSP2 instance to a list of KSP1 instances in #3797).Changes
Now instead of using the column's own index property, the show/hide helper function has an index parameter, into which we pass the index of the next column in the normal layout that is always visible. This makes the columns hide and reappear properly without exceptions.