Skip to content

Commit

Permalink
Merge pull request #2592 from cwensley/curtis/fix-removing-from-table…
Browse files Browse the repository at this point in the history
…layout-before-created

Further fixes removing controls from TableLayout
  • Loading branch information
cwensley committed Dec 6, 2023
2 parents 501bd2d + 44f6801 commit 4b733ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Eto.WinForms/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/Eto.Wpf/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 4b733ae

Please sign in to comment.