This documentation is archived and is not being maintained.

TableLayoutPanel.SetColumn Method

Sets the column position of the specified child control.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public void SetColumn (
	Control control,
	int column
public void SetColumn (
	Control control, 
	int column
public function SetColumn (
	control : Control, 
	column : int
Not applicable.



The control to move to another column.


The column to which control will be moved.

The SetColumn method moves the control to another column in the TableLayoutPanel. The columns and rows have zero-based indexes. Setting the column position to -1 specifies that the control will flow to the first empty cell.

This method reapplies the table layout to all controls in the TableLayoutPanel.

This method is called by the Column property, which the panel adds to its child controls at design time.

The following code example uses the SetColumn method to swap two controls contained within a TableLayoutPanel control. The example assumes a TableLayoutPanel control with at least two rows.

private void swapControlsBtn_Click(
    System.Object sender, 
    System.EventArgs e)
    Control c1 = this.TableLayoutPanel1.GetControlFromPosition(0, 0);
    Control c2 = this.TableLayoutPanel1.GetControlFromPosition(0, 1);

    if( c1 != null && c2 != null )
        this.TableLayoutPanel1.SetColumn(c2, 0);
        this.TableLayoutPanel1.SetColumn(c1, 1);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0