Windows Develop Bookmark and Share   
 index > Windows Forms General > removing rows from TableLayoutPanel
 

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 reportsthe 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

Craig Throne  Friday, July 07, 2006 4:56 PM
The last row (and last column) will always expand to fill the rest of the panel.
Peter Ritchie  Friday, July 07, 2006 6:10 PM
The panel is already filled though, the scrollbars are present.
Craig Throne  Friday, July 07, 2006 6:29 PM
If GrowStyle is set to TableLayoutPanelGrowStyle.AddRows then the panel will grow to fit new rows; but won't shrink when rows are removed.
Peter Ritchie  Friday, July 07, 2006 6:41 PM
You need to set AutoScroll = false, remove rows, then set AutoScroll = true. This will force the panel to recalculate the correct size.
DallasJerry  Thursday, September 24, 2009 10:37 PM

You can use google to search for other answers

Custom Search

More Threads

• Problem WithEvents using forms
• help ToolStripDropDounButton
• Drag and Drop with multiple ListViews
• Webbrowser Help needed
• How to make Invoice Form
• Identify Components in a Form
• Threads and Timers
• MonthCalendar Control redraw problem (beta 2)
• Performance issue when using RichTextBox.LoadFile method to load a large *.rtf file.
• GridView has no AutoFormat?