Reputation: 3211
My application uses a TableLayoutPanel that resides within a TabPage.
If the number of items I add is relatively small (i.e. it doesn't "fill up" the whole tab page) then the last row's height is stretched. Here is a screenshot of what's happening:
I have tried to change the properties of the table to Autosize, GrowAndShrink, etc. but nothing seems to stop this from happening.
Here are my current settings for the layout properties of the table:
How can I get the last row to be the same size as the other rows?
Thanks
Upvotes: 9
Views: 9550
Reputation: 1
1 pixel is the minimum unit!
eg: 10 rows to average container height, if the TableLayoutPanel
's height is 200, it's perfect!
But if the TableLayoutPanel
's height is 199, the computer is unable to split one pixel, so every row's height must be 19, while the last row's height is 19+(199 - 19*10)= 28
.
As a result: the last row is 10 pixels taller than the other rows.
What we need to do is avoid setting the TableLayoutPanel
's height to something that is unable to average. Or we need to change the TableLayoutPanel
height!
Upvotes: 0
Reputation: 551
I just had very similar problem. Filling TableLayoutPanel
programatically (with autoscroll) and the last row was too high. Dock work-around was not suitable for me.
Fixed by adding empty Label
as the last row. It "occupies" the last row, but is not visible. Enough for me.
Upvotes: 7
Reputation: 1148
Using the dock property solves the last row height problem, but creates another by changing the table width to match the container width (100%). I wanted the height in the last row to be correct but I do not want the forced 100% width.
Instead of using the Dock property, I used:
AutoSizeMode = AutoSizeMode.GrowAndShrink
That made the autosize work correctly on the last row and column.
Upvotes: 5
Reputation: 357
I had a similar problem where the last row was always too high in a TLP with more rows than could fit, using AutoScroll.
The solution was to turn AutoScroll off, set the row sizes from the TLP Rows collection, then turn AutoScroll back on again.
Upvotes: 2
Reputation: 6489
Based on your design and your requirements I suggest you to make Dock
property of TableLayoutPanel
to top.
Upvotes: 4