Reputation: 1929
Good day!
We have a tableLayoutPanel, that is being use to add combo boxes and labels in runtime.
When the user clicks the button, what our code does is that, it creates the controls in runtime, and then it adds it to tableLayoutPanel's container.. When we click the 'Add' button once, we should see one cell created just like below
Now, when we add multiple controls, we notice that row 0 accumulates a large space. How do we remove that?
notice that program1 has large space, but program 2,3,4 have evenly space.. Why is that so? Thanks
Here is our code when the user clicks the 'Add' button
int cLeft = 1;
public System.Windows.Forms.ComboBox AddNewComboBox()
{
System.Windows.Forms.Label lab = new System.Windows.Forms.Label();
System.Windows.Forms.ComboBox com = new System.Windows.Forms.ComboBox();
tableLayoutPanel1.Controls.Add(lab,0,cLeft-1);
lab.Text = "Program " + cLeft.ToString() + ":";
lab.Name = "label" + cLeft.ToString();
tableLayoutPanel1.Controls.Add(com,1,cLeft-1);
com.Width = 220;
com.Name = "comboBox " + cLeft.ToString();
cLeft = cLeft + 1;
return com;
}
Upvotes: 1
Views: 70
Reputation: 3153
I encountered a similar problem once. I think the problem is that the first row you insert is auto sized. If you add a blank row at the beginning that is auto sized and all the controls afterwards with a fixed size it should work.
Alternatively you could create an own UserControl wherein you place your label and combobox and add this with a maxheight to your tablelayout panel.
Upvotes: 1