DataGrid.PreferredColumnWidth Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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.

Exception Condition
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
Available since 1.1
Return to top
Show: