DataGridViewButtonColumn.DefaultCellStyle Property

Definition

Gets or sets the column's default cell style.

[System.ComponentModel.Browsable(true)]
public override System.Windows.Forms.DataGridViewCellStyle DefaultCellStyle { get; set; }

Property Value

The DataGridViewCellStyle to be applied as the default style.

Attributes

Examples

The following code example demonstrates the use of this property.

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();
}

Remarks

The default DataGridViewCellStyle returned by this property has an initial Alignment property value of MiddleCenter. This value overrides the value specified in the DefaultCellStyle property of the DataGridView control, but may be overridden by other cell style properties. For more information, see Cell Styles in the Windows Forms DataGridView Control.

Poznámka

When visual styles are enabled, the buttons in a button column are painted using a ButtonRenderer and cell styles specified through properties such as DefaultCellStyle have no effect.

Applies to

Produkt Verze
.NET Framework 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, 3.1, 5, 6, 7, 8, 9, 10

See also