DataGridViewBand.DefaultCellStyle Property

Definition

Gets or sets the default cell style of the band.

C#
[System.ComponentModel.Browsable(false)]
public virtual System.Windows.Forms.DataGridViewCellStyle DefaultCellStyle { get; set; }

Property Value

The DataGridViewCellStyle associated with the DataGridViewBand.

Attributes

Examples

The following code example sets the default cell style for the first column in a DataGridView.

C#
// Freeze the first row.
private void Button4_Click(object sender, System.EventArgs e)
{

    FreezeBand(dataGridView.Rows[0]);
}

private void Button5_Click(object sender, System.EventArgs e)
{

    FreezeBand(dataGridView.Columns[1]);
}

private static void FreezeBand(DataGridViewBand band)
{
    band.Frozen = true;
    DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.BackColor = Color.WhiteSmoke;
    band.DefaultCellStyle = style;
}

Remarks

The default cell style is applied to cells that do not have an associated style. When getting this property, a DataGridViewCellStyle with default values will be created if the default cell style does not exist.

Applies to

Product Versions
.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