DataGridViewColumn.Width Property

Definition

Gets or sets the current width of the column.

C#
public int Width { get; set; }

Property Value

The width, in pixels, of the column. The default is 100.

Exceptions

The specified value when setting this property is greater than 65536.

Examples

The following code example sets the width of a column. This code example is part of a larger example provided for the DataGridViewColumn class.

C#
// Set the width.
private void Button5_Click(object sender, System.EventArgs e)
{
    DataGridViewColumn column = dataGridView.Columns[0];
    column.Width = 60;
}

Remarks

If the specified value when setting this property is less than the value of the MinimumWidth property, the MinimumWidth property value is used instead.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also