PreferredColumnWidth Property

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)

public int PreferredColumnWidth { get; set; }

Property Value

Type: System.Int32

The default width (in pixels) of columns in the grid.

Exception Condition

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
Available since 1.1
Return to top
© 2015 Microsoft