I have a TableLayoutPanel control that has a row with x columns. Each cell inside has a Panel control.
I want to exchange a column x with column y in run time.

How can I do this?

Once again, the question was: How to change columns' order in a tablelayoutPanel?

有帮助吗?

解决方案

If you have a reference to each Panel control use those and skip the first two lines of the code below (ie. the GetControlFromPosition() function I've used below to get the reference to the Controls) -

Control ctr1 = tableLayoutPanel1.GetControlFromPosition(0, 0);
Control ctr2 = tableLayoutPanel1.GetControlFromPosition(1, 1);

tableLayoutPanel1.SetCellPosition(ctr1, new TableLayoutPanelCellPosition(1, 1));
tableLayoutPanel1.SetCellPosition(ctr2, new TableLayoutPanelCellPosition(0, 0));

Replace the 0's and 1's with Row and Column Index where you want to place the control..

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top