Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move row in TableLayoutPanel

I can't figure out how to move a row of the TableLayoutPanel in the Designer. How do you do that?

I cannot drag them, there are no buttons to move them up or down and moving all the controls from one row to another is just tedious and time consuming.

like image 941
Thomas Glaser Avatar asked Oct 24 '12 10:10

Thomas Glaser


2 Answers

To do it in the designer, you need a third, empty row to use, let's say you want to swap row 1 and row 2.

  • Add an empty row 3.
  • Move controls from row 1 > row 3
  • Move controls from row 2 > row 1
  • Move controls from row 3 > row 1
  • Remove row 3

Yes, it's a workaround but it gets the job done.

Alternatively, you can change your code in the designer.cs file. There you can change the following:

this.myTableLayout.Controls.Add(this.myLabel1, 0, 0);//Change the order of these items.
this.myTableLayout.Controls.Add(this.myLabel2, 0, 1);
like image 187
Carra Avatar answered Nov 15 '22 13:11

Carra


If your TableLayoutPanel's child controls are not docked (i.e., you can drag them around), you can simply drag each control from your first row to the corresponding cell in the second. The Windows Forms designer will then swap the controls for you, since you can only have one control in each cell. This tip can also be found on MSDN.

It's still not ideal, but at least you don't have to create or remove rows with this method, nor manually edit the designer code.

like image 27
Knowledge Cube Avatar answered Nov 15 '22 13:11

Knowledge Cube