DataGridViewColumn.DefaultCellStyle Property
Gets or sets the column's default cell style.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
[BrowsableAttribute(true)] public override DataGridViewCellStyle DefaultCellStyle { get; set; }
Property Value
Type: System.Windows.Forms.DataGridViewCellStyleA DataGridViewCellStyle that represents the default style of the cells in the column.
The DataGridView control displays its cells using the styles indicated by the cell InheritedStyle property, which inherits styles from other properties of type DataGridViewCellStyle. For cells in this column, the styles specified through the DefaultCellStyle property override the styles specified through the DataGridView.DefaultCellStyle property, but are overridden by the styles specified through the DataGridView.RowsDefaultCellStyle, DataGridView.AlternatingRowsDefaultCellStyle, DataGridViewRow.DefaultCellStyle, and DataGridViewCell.Style properties.
For more information, see Cell Styles in the Windows Forms DataGridView Control.
The following code example uses the DefaultCellStyle property to set the content alignment of various columns.
private void ChangeColumnAlignment() { songsDataGridView.Columns["Title"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter; songsDataGridView.Columns["Title"].Name = DataGridViewContentAlignment.BottomCenter.ToString(); songsDataGridView.Columns["Artist"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft; songsDataGridView.Columns["Artist"].Name = DataGridViewContentAlignment.BottomLeft.ToString(); songsDataGridView.Columns["Album"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight; songsDataGridView.Columns["Album"].Name = DataGridViewContentAlignment.BottomRight.ToString(); songsDataGridView.Columns["Release Date"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; songsDataGridView.Columns["Release Date"].Name = DataGridViewContentAlignment.MiddleCenter.ToString(); songsDataGridView.Columns["Track"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; songsDataGridView.Columns["Track"].Name = DataGridViewContentAlignment.MiddleLeft.ToString(); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.