From 3a8419e6e9eefa6e08b29c7bb4b2abfdd780d272 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 5 Oct 2026 12:47:56 -0400 Subject: [PATCH] fix(ui): show the newly selected plate when a Plates row is chosen The plate preview read DataGridView.CurrentRow in SelectionChanged, but that event runs before CurrentCell moves, so CurrentRow still named the previous row. Choosing a row showed the plate that had been selected before it, and the next-plate button snapped the preview back to the old plate. Read the selected row instead. The Windows job of run 37341610182 caught it: PlatePreview_StepsThroughThePlates_AndFollowsThePlatesTable expected "Plate 2 of 2" after the next-plate button and got "Plate 1 of 2". The test now also checks that the selected row follows the button. --- OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs | 1 + OpenNest/Forms/SavedNestsForm.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs b/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs index 64295ca..9956a1c 100644 --- a/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs +++ b/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs @@ -85,6 +85,7 @@ public class SavedNestsFormTests Assert.Equal("Plate 2 of 2", label.Text); Assert.Single(preview.Plate.Parts); Assert.Equal(1, plates.CurrentRow!.Index); + Assert.Equal(1, plates.SelectedRows[0].Index); Assert.True(previous.Enabled); Assert.False(next.Enabled); diff --git a/OpenNest/Forms/SavedNestsForm.cs b/OpenNest/Forms/SavedNestsForm.cs index 2a8c5c3..6da1886 100644 --- a/OpenNest/Forms/SavedNestsForm.cs +++ b/OpenNest/Forms/SavedNestsForm.cs @@ -139,8 +139,10 @@ public sealed class SavedNestsForm : Form AddColumn(platesGrid, "Utilization", "Utilization", 90, typeof(double), alignRight: true, format: "P1"); platesGrid.SelectionChanged += (_, _) => { - if (platesGrid.CurrentRow is { } row) - ShowPlate(row.Index); + // Read the selected row: while this event runs, CurrentRow still names the + // previously current row. + if (SelectedPlateRow() is var row and >= 0) + ShowPlate(row); }; drawingsGrid = CreateGrid(); @@ -641,10 +643,12 @@ public sealed class SavedNestsForm : Form plateLabel.Text = $"Plate {index + 1:N0} of {previewPlates.Count:N0}"; previousPlateButton.Enabled = index > 0; nextPlateButton.Enabled = index < previewPlates.Count - 1; - if (index < platesGrid.Rows.Count && platesGrid.CurrentRow?.Index != index) + if (index < platesGrid.Rows.Count && SelectedPlateRow() != index) platesGrid.CurrentCell = platesGrid.Rows[index].Cells[0]; } + private int SelectedPlateRow() => platesGrid.SelectedRows.Count > 0 ? platesGrid.SelectedRows[0].Index : -1; + private void OpenSelected() { if (SelectedNestId() is not Guid id)