DataGrid.PreferredColumnWidth Property

Definition

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

C#
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.DataGridPreferredColumnWidthTypeConverter))]
public int PreferredColumnWidth { get; set; }

Property Value

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

Attributes

Exceptions

The property value is less than 0.

Examples

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

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

Remarks

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.

Applies to

Product Versions
.NET Framework 1.1, 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, 10

See also