diff --git a/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs b/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs index cc9747f97..39701a4a6 100644 --- a/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs +++ b/src/Eto.Gtk/Forms/TableLayoutHandler.gtk3.cs @@ -152,6 +152,9 @@ bool Attach(Control child, int x, int y) public void Remove(Control child) { + if (controls == null) + return; + for (int y = 0; y < controls.GetLength(0); y++) { for (int x = 0; x < controls.GetLength(1); x++) diff --git a/src/Eto.Mac/Forms/TableLayoutHandler.cs b/src/Eto.Mac/Forms/TableLayoutHandler.cs index cfb2b0bd7..8dd3c01ef 100644 --- a/src/Eto.Mac/Forms/TableLayoutHandler.cs +++ b/src/Eto.Mac/Forms/TableLayoutHandler.cs @@ -347,6 +347,8 @@ public void Move(Control child, int x, int y) public void Remove(Control child) { + if (views == null) + return; for (int y = 0; y < views.GetLength(0); y++) for (int x = 0; x < views.GetLength(1); x++) { diff --git a/src/Eto.WinForms/Forms/TableLayoutHandler.cs b/src/Eto.WinForms/Forms/TableLayoutHandler.cs index 02caa532d..a1ee2f0b5 100644 --- a/src/Eto.WinForms/Forms/TableLayoutHandler.cs +++ b/src/Eto.WinForms/Forms/TableLayoutHandler.cs @@ -272,7 +272,8 @@ public void Remove(Control child) if (childControl.Parent == Control) { var pos = Control.GetCellPosition(childControl); - views[pos.Column, pos.Row] = null; + if (views != null) + 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 ad86eb2fb..ed83fddd2 100755 --- a/src/Eto.Wpf/Forms/TableLayoutHandler.cs +++ b/src/Eto.Wpf/Forms/TableLayoutHandler.cs @@ -361,6 +361,8 @@ public Padding Padding void Remove(int x, int y) { + if (controls == null) + return; var control = controls[x, y]; if (control != null) { diff --git a/src/Eto/Forms/Controls/Control.cs b/src/Eto/Forms/Controls/Control.cs index 7318db361..004f76b6f 100755 --- a/src/Eto/Forms/Controls/Control.cs +++ b/src/Eto/Forms/Controls/Control.cs @@ -991,8 +991,8 @@ internal set /// public void Detach() { - if (VisualParent != null) - VisualParent.Remove(this); + VisualParent?.Remove(this); + Parent?.Remove(this); } static readonly object IsAttached_Key = new object();