Width Property

ColumnHeader.Width Property


Gets or sets the width of the column.

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

public int Width { get; set; }

Property Value

Type: System.Int32

The width of the column, in pixels.

This property enables you to set the Width of the ColumnHeader. The ColumnHeader can be set to adjust at run time to the column contents or heading. To adjust the width of the longest item in the column, set the Width property to -1. To autosize to the width of the column heading, set the Width property to -2.


Unexpected behavior can result when the combined width of all columns exceeds 32,768 pixels.

The following code example demonstrates initializing a ListView control. The example creates ColumnHeader objects and sets the column header's Text, TextAlign and Width properties. The example also adds items and subitems to the ListView. To run this example paste the following code in a form and call the PopulateListView method from the form's constructor or Load event handler.

Snippet section 1 of code snippet {"project_id":"3fedad16-eaf1-41a6-8f96-0c1949c68f32","entity_id":"b913419a-5dc3-4318-ae90-fbc75176961c","entity_type":"CodeSnippet","locale":"en-US"} in source file ({"filename":"/CS/form1.cs","blob_type":"Source","blob_id":"-002fcs-002fform1-002ecs","blob_revision":3}) overlaps with other snippet sections. Ensure the tags are placed correctly.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft