From 44f6801171bca1493c63b83ac0220a312edcfaa8 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Wed, 6 Dec 2023 12:51:03 -0800 Subject: [PATCH] Further fixes removing controls from TableLayout --- src/Eto.WinForms/Forms/TableLayoutHandler.cs | 2 +- src/Eto.Wpf/Forms/TableLayoutHandler.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Eto.WinForms/Forms/TableLayoutHandler.cs b/src/Eto.WinForms/Forms/TableLayoutHandler.cs index a1ee2f0b5..9ddbbef2c 100644 --- a/src/Eto.WinForms/Forms/TableLayoutHandler.cs +++ b/src/Eto.WinForms/Forms/TableLayoutHandler.cs @@ -272,7 +272,7 @@ public void Remove(Control child) if (childControl.Parent == Control) { var pos = Control.GetCellPosition(childControl); - if (views != null) + if (views != null && ReferenceEquals(views[pos.Column, pos.Row], child)) views[pos.Column, pos.Row] = null; childControl.Parent = null; SetEmptyCell(pos.Column, pos.Row); diff --git a/src/Eto.Wpf/Forms/TableLayoutHandler.cs b/src/Eto.Wpf/Forms/TableLayoutHandler.cs index ed83fddd2..b50928d1e 100755 --- a/src/Eto.Wpf/Forms/TableLayoutHandler.cs +++ b/src/Eto.Wpf/Forms/TableLayoutHandler.cs @@ -423,10 +423,20 @@ public void Remove(Control child) public override void Remove(sw.FrameworkElement child) { + // ensure this is actually a child of this table + if (child.Parent != Control) + return; + + // row and column could be for a different table var x = swc.Grid.GetColumn(child); var y = swc.Grid.GetRow(child); Control.Children.Remove(child); - controls[x, y] = null; + if (controls != null + && x >= 0 && x < controls.GetLength(0) + && y >= 0 && y < controls.GetLength(1) + && ReferenceEquals(controls[x,y]?.GetContainerControl(), child) + ) + controls[x, y] = null; OnChildPreferredSizeUpdated(); } }