Pergunta

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?

Foi útil?

Solução

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..

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top