ali motamedi
ali motamedi

Reputation: 103

Table Layout Panel Wrong Column ordering

i have a table layoutpanel in my form. it has a few rows (filled with controls):

label10   ---   textbox10     ----    label20
label11   ---    textbox11   ---    label21
label12    ---   textbox12   ---    label22
label13    ---   textbox13    ---   label23
label14    ---   textbox14    ---   label24

now i want to add new row in the middle of table using this code:

myLayoutpanel.Controls.Add(label333, 0, 3);

myLayoutpanel.Controls.Add(textbox333, 0, 3);

myLayoutpanel.Controls.Add(label444, 0, 3);

it will add a new row after line3. usually the result is in the true order:

label333   ---   textbox333   ---   label444

but for some rows it seems wrong: for example if the addition take place after line 4 :

label444  ---    label333   ---   textbox333     

Upvotes: 2

Views: 1529

Answers (2)

Nicholas Piasecki
Nicholas Piasecki

Reputation: 25583

You're not going crazy. This is a bug introduced in the .NET Framework 4.5. See references at

A .NET 4.5 incompatibility

and

System.Windows.Forms.TableLayoutPanel Behavior Change .NET 4.5 Framework

Upvotes: 3

Amir
Amir

Reputation: 788

I don't know why this happened to you as you post no evidence. But please check if this code execute correctly. I conjecture that your codes hadn't executed in right order.

myLayoutpanel.Controls.Add(label333, 0, 3); 
Thread.Sleep(100); 
myLayoutpanel.Controls.Add(textbox333, 0, 3); 
Thread.Sleep(100); 
myLayoutpanel.Controls.Add(label444, 0, 3); 

Upvotes: 0

Related Questions