removing rows from TableLayoutPanel

At runtime, whenever I remove a row from a TableLayoutPanel, the actual size of the last row is increasing.

The table is intialized as follows:

_table.AutoScroll = true;
_table.AutoSize = false;
_table.RowCount = 10;
for (int j = 0; j < 10; j ++)
{
_table.RowStyles.Add(
new RowStyle(System.Windows.Forms.SizeType.Absolute, DEFAULT_HEIGHT));
}

The remove code is as follows:

void RemoveLastRow()
{
_table.RowCount = _table.RowCount -1
_table.RowStyles.RemoveAt(_table.RowStyles.Count - 1);
}

After I do the remove, the new last row now has a height that is double what it used to be. The RowStyle for this row still reports DEFAULT_HEIGHT, but the GetRowHeights method reports the new size. The combined heights of all of the rows is greater than the Size (vertical scroll bar is present), so the last row is not increasing to fill out the area of the control.

Any thoughts would be appreciated.

--Craig



Answer this question

removing rows from TableLayoutPanel

  • Koruyucu

    The last row (and last column) will always expand to fill the rest of the panel.

  • Pauly C

    If GrowStyle is set to TableLayoutPanelGrowStyle.AddRows then the panel will grow to fit new rows; but won't shrink when rows are removed.

  • DD_Helmetman

    The panel is already filled though, the scrollbars are present.
  • removing rows from TableLayoutPanel