Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,
In TableLayoutPanel if we set AutoSize = true and Dock = fill
then last column/row will occupy all remaining space.
How to set it to required height (row) and width (column)?
Posted
Updated 22-Oct-18 16:22pm

I found it.....
add tablelayoutpanel as tbl1 with two row and two column.
set its dock = fill autoscroll = true
and set width for 1st row autosize and for second absoluto 0.00 F
same for column 1 and 2.
now add actual tablelayoytpanel in 1st rows 1st column.
 
Share this answer
 
Excellent :-)

Solution above works...

Rest of my code...

Adding a row and setting rowstyle...

CustomButton is a buttoncontrol in a collection of buttons...

C#
foreach (CustomButton b in buttons)
    {
        b.Dock = DockStyle.Top;
        AddRow(b);
    }
}

private void AddRow(CustomButton b)
{
    int rowIndex = AddTableRow();
   tableLayoutPanel.Controls.Add(b, 0, rowIndex);
}

private int AddTableRow()
{
    int index = tableLayoutPanel.RowCount++;
    RowStyle style = new RowStyle(SizeType.AutoSize);
    tableLayoutPanel.RowStyles.Add(style);
    return index;
}
 
Share this answer
 
In my case,

I changed autoscroll option After I removed one row

like this,
tb1.RowCount = tb1.RowCount - 1
tb1.RowStyles.RemoveAt(tb1.RowStyles.Count - 1)
tb1.AutoScroll = False
tb1.AutoScroll = True

and then it works.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900