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)