This documentation is archived and is not being maintained.

TableLayoutPanel.ColumnStyles Property

Note: This property is new in the .NET Framework version 2.0.

Gets a collection of column styles for the TableLayoutPanel.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public TableLayoutColumnStyleCollection ColumnStyles { get; }
/** @property */
public TableLayoutColumnStyleCollection get_ColumnStyles ()

public function get ColumnStyles () : TableLayoutColumnStyleCollection

Property Value

A TableLayoutColumnStyleCollection containing a ColumnStyle for each column in the TableLayoutPanel control.

Use the ColumnStyles property to access the style properties of specific columns. You can use members of the ColumnStyle class to set the characteristics of individual columns in the table.

When the TableLayoutPanel control arranges its columns, it assigns priorities to each ColumnStyle in the following order:

  1. Columns with ColumnStyle set to Absolute are considered first, and their fixed widths are allocated.

  2. Columns with ColumnStyle set to AutoSize are sized to their contents.

  3. Remaining space is divided among columns with ColumnStyle set to Percent.

The following code example sets the ColumnStyle properties of each column when a Button is clicked.

private void toggleColumnStylesBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    TableLayoutColumnStyleCollection styles = 
        this.TableLayoutPanel1.ColumnStyles;

    foreach( ColumnStyle style in styles )
    {
        if( style.SizeType == SizeType.Absolute )
        {
            style.SizeType = SizeType.AutoSize;
        }
        else if( style.SizeType == SizeType.AutoSize )
        {
            style.SizeType = SizeType.Percent;

            // Set the column width to be a percentage
            // of the TableLayoutPanel control's width.
            style.Width = 33;
        }
        else
        {
            // Set the column width to 50 pixels.
            style.SizeType = SizeType.Absolute;
            style.Width = 50;
        }
    }
}

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Show: