I've been fighting with this for a while, and have found that a number of other people struggle with the TableLayoutPanel (.net 2.0 Winforms) as well.
Problem
I am attempting to take a 'blank' tablelayoutpanel, which has 10 columns defined, then at runtime programatically add rows of controls (i.e. one control per cell).
One might have thought that it should be as simple as
myTableLayoutPanel.Controls.Add(myControl, 0 /* Column Index */, 0 /* Row index */);
But that (for me) doesn't add the rows. So maybe adding in a row style
myTableLayoutPanel.RowStyles.Clear();
myTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
But that doesn't work either. I've dug around and found out that the myTableLayoutPanel.RowCount
usage changes from design time to run time, hence doing myTableLayoutPanel.RowCount++;
doesn't actually add another row, not even before/after adding a RowStyle entry for it!
Another related issue I am encountering is that the controls will be added to the display, but they all simply get rendered at point 0,0 of the TableLayoutPanel, additionally they are not even constrained to be within the Cell bounds that they are supposed to be displayed within (i.e. with Dock = DockStyle.Fill they still appear way too large/small).
Does someone have a working example of adding rows & controls at runtime?
Cheers