Bug in TableLayoutPanel

  • Thread starter Thread starter Timothy V
  • Start date Start date
T

Timothy V

Hi all,
I don't usually post possible bugs because I would assume that there are
none. However, some of the properties are not acting acting as they should.

Here is what I have found. When using the AutoSize property set to "true",
and the GrowStyle property set to "AddColumns" or "AddRows" (default). You
add a control (such as a button) with:
this.tableLayoutPanel1.Controls.Add(new Button());

What this does is add the button to newly made cell (a cell in a new row if
"GrowStyle=AddRows" OR in a new column if "GrowStyle=AddColumns").

Lets add about 5 of these buttons. When we call:
this.tableLayoutPanel1.ColumnStyles.Count;
we should get an int that has 5 in it, right? Wrong. It is 0 (zero).

Am I using this wrong? Because strange enough, the controls are showing up
when I run the application.

I would be very interested in some comments on this.

Thanks all,
Tim.
 
Are you looking to get the number of columns? Or the number of
columnStyles... which is what you are getting. Concidering that no
columnStyles have been added, only columns, I would expect ColumnStyles.Count
to return 0.

-CA
 
Thanks for your response... Your explaination sounds pretty much on the
ball. I have changed my column adding code to:
int i = tablelayoutpanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent,
50.0F));
tlp.Controls.Add(c, i, 0);

This now works fine with ColumnStyles.Count, giving the correct answer.
HOWEVER, I can't seem to get ColumnStyles.RemoveAt() to work.

From what you said previously, and from my understanding now, it is removing
the ColumnStyle, not the Column. How do I remove a column?

Thanks in advance,
Tim.
 
Back
Top