Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataGrid.PreferredColumnWidth Property

Gets or sets the default width of the grid columns in pixels.

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

[TypeConverterAttribute(typeof(DataGridPreferredColumnWidthTypeConverter))]
public int PreferredColumnWidth { get; set; }

Property Value

Type: System.Int32
The default width (in pixels) of columns in the grid.

ExceptionCondition
ArgumentException

The property value is less than 0.

Set this property before resetting the DataSource and DataMember properties (either separately, or through the SetDataBinding method), or the property will have no effect.

The property cannot be set to a value less than 0.

The following code example sets the default column widths to a value passed to the method.

Private Sub SetDefaultColWidth(defColWidth As Integer)
    DataGrid1.PreferredColumnWidth = defColWidth
 End Sub
   

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft