vvavepacket
vvavepacket

Reputation: 1929

row0 of tableLayoutPanel keeps getting large

Good day!

We have a tableLayoutPanel, that is being use to add combo boxes and labels in runtime.

enter image description here

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

enter image description here

Now, when we add multiple controls, we notice that row 0 accumulates a large space. How do we remove that?

enter image description here enter image description here enter image description here enter image description here

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

Answers (1)

Bongo
Bongo

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

Related Questions