From 30e59e681034078f143afde64c1c79eef916aaaa Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Tue, 10 Sep 2024 13:54:54 -0700 Subject: [PATCH] Wpf: Fix issue restoring column focus if the column has been removed --- src/Eto.Wpf/Forms/Controls/GridHandler.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Eto.Wpf/Forms/Controls/GridHandler.cs b/src/Eto.Wpf/Forms/Controls/GridHandler.cs index 9edf1886e..e57c292d4 100755 --- a/src/Eto.Wpf/Forms/Controls/GridHandler.cs +++ b/src/Eto.Wpf/Forms/Controls/GridHandler.cs @@ -847,7 +847,13 @@ protected void RestoreColumnFocus() { Control.CurrentColumn = null; if (Control.Columns.Count > 0) - Control.CurrentCell = new swc.DataGridCellInfo(Control.SelectedItem, CurrentColumn ?? Control.CurrentColumn ?? Control.Columns[0]); + { + // ensure the saved column still exists in the grid, it could be removed by user logic + if (CurrentColumn != null && Control.Columns.Contains(CurrentColumn)) + Control.CurrentCell = new swc.DataGridCellInfo(Control.SelectedItem, CurrentColumn); + else + Control.CurrentCell = new swc.DataGridCellInfo(Control.SelectedItem, Control.CurrentColumn ?? Control.Columns[0]); + } CurrentColumn = null; }