Move row in TableLayoutPanel
Asked Answered
V

2

6

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.

Vaudeville answered 24/10, 2012 at 10:55 Comment(2)
Another tedious task is opening the .Designer.cs file and moving them there, but perhaps easier nonetheless?Caracal
You can't move a row. You can move the controls that are in a row to another row.Randolphrandom
A
7

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);
Anallese answered 24/10, 2012 at 15:55 Comment(0)
P
1

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.

Petitionary answered 1/6, 2016 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.