From 8ddba71d512e5f1be1019613d2b5bc1cb34bef52 Mon Sep 17 00:00:00 2001 From: Lee Richardson Date: Mon, 15 Apr 2024 17:17:05 +0100 Subject: [PATCH] Handle some nulls --- src/Eto.Gtk/Forms/Controls/GridHandler.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Eto.Gtk/Forms/Controls/GridHandler.cs b/src/Eto.Gtk/Forms/Controls/GridHandler.cs index ee828ce49..5389bbcfd 100644 --- a/src/Eto.Gtk/Forms/Controls/GridHandler.cs +++ b/src/Eto.Gtk/Forms/Controls/GridHandler.cs @@ -145,7 +145,10 @@ protected override void Initialize() if (!AllowEmptySelection && AllowMultipleSelection && Control.Selection.CountSelectedRows() == 0) { Control.GetCursor(out var cursorRow, out _); - Control.Selection.SelectPath(cursorRow); + if (cursorRow != null) + { + Control.Selection.SelectPath(cursorRow); + } } }; @@ -737,11 +740,12 @@ private void SetSelectionMode(bool allowEmptySelection, bool allowMultipleSelect && newMode is Gtk.SelectionMode.Single or Gtk.SelectionMode.Browse) { Control.GetCursor(out var cursorRowPath, out _); - var cursorWasSelected = Control.Selection.PathIsSelected(cursorRowPath); + var mustReselectCursor = cursorRowPath != null && Control.Selection.PathIsSelected(cursorRowPath); Control.Selection.Mode = Gtk.SelectionMode.None; Control.Selection.Mode = newMode; - if (cursorWasSelected) + + if (mustReselectCursor) { Control.Selection.SelectPath(cursorRowPath); }