Set default height of rows in TableLayoutPanel
<p>How can I set default height of all <code>TableLayoutPanel</code> rows in c# to 16px?</p>

<p>Usually I would do:</p>

<pre><code>for (int i = 0; i &lt; amount_of_rows; i++)
{
    panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 16));
}
</code></pre>

<p>But in my case I have 8 columns and unknown amount of rows. Amount on rows is known after all controls are added, not before.</p>

<p>This is my code:</p>

<pre><code>TableLayoutPanel panel = new TableLayoutPanel
{
    BackColor = SystemColors.Control,
    CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
    AutoScroll = true,
    Width = 500,
    Location = new Point(-1, -1),
    ColumnCount = 8
};
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 16));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 73));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 16));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 73));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 38));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 38));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 52));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 52));

int amountOfRows = 0;
for (...)
{
    // a lot of code which populates panel with generated controls and counts amountOfRows
}
panel.RowCount = amountOfRows;
Controls.Add(panel);
</code></pre>

<p>Such code creates rows with 24px height.</p>

<p>Adding ColumnStyles to table after it was populated like this:</p>

<pre><code>for (int i = 0; i &lt; amountOfRows ; i++)
{
    panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 16));
}
</code></pre>

<p>works but it makes last row very large.</p>

<p>EDIT: example code including adding a control:</p>

<pre><code>TableLayoutPanel panel = new TableLayoutPanel
{
    BackColor = SystemColors.Control,
    CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
    AutoScroll = true,
    Width = 500,
    Location = new Point(-1, -1),
    ColumnCount = 8,
    Margin = new Padding(0),
    Padding = new Padding(0)
};
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 16));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 73));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 16));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 73));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 38));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 38));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 52));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 52));

for (int i = 0; i &lt; 10; i++) // lets assume we don't know it will be added 10x
{
    CheckBox exchangeEnabled = new CheckBox
    {
        Margin = new Padding(0),
        Padding = new Padding(0),
        Dock = DockStyle.Fill,
        CheckAlign = ContentAlignment.MiddleCenter
    };
    panel.Controls.Add(exchangeEnabled, 0, i);
}
Controls.Add(panel);
</code></pre>