Collapse the table of content
Expand the table of content
Expand Minimize

DataGridView.ColumnHeadersDefaultCellStyle Property


Gets or sets the default column header style.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public DataGridViewCellStyle ColumnHeadersDefaultCellStyle { get; set; }

Property Value

Type: System.Windows.Forms.DataGridViewCellStyle

A DataGridViewCellStyle that represents the default column header style.

The default DataGridViewCellStyle returned by this property has the following initial property values:

DataGridViewCellStyle property

Default value


The value of the SystemBrushes.Control property.


The value of the SystemBrushes.WindowText property.


The value of the SystemBrushes.Highlight property.


The value of the SystemBrushes.HighlightText property.


The value of the Font property.





These values automatically override the values set through the DefaultCellStyle property. To force column headers to inherit the DefaultCellStyle values, you must set the values in the ColumnHeadersDefaultCellStyle object to the default values indicated for the DataGridViewCellStyle class.

For more information about cell style inheritance, see Cell Styles in the Windows Forms DataGridView Control.

If visual styles are enabled and EnableHeadersVisualStyles is set to true, all header cells except the TopLeftHeaderCell are painted using the current theme and the ColumnHeadersDefaultCellStyle values are ignored.

Legacy Code Example

The following code example demonstrates how to set the ColumnHeadersDefaultCellStyle, AutoSizeRowsMode, ColumnHeadersBorderStyle, CellBorderStyle, GridColor, BackgroundColor, RowHeadersVisible, SelectionMode, ColumnCount, and MultiSelect properties. In addition, the code example demonstrates how to set the DataGridViewColumn.Name and DataGridViewColumn.DefaultCellStyle properties. To run this example, paste the code into a form that contains a DataGridView named dataGridView1, and then call the SetUpDataGridView method from the form's constructor or Load event handler. Ensure all events are associated with their event handlers.

private void SetUpDataGridView()
    dataGridView1.ColumnCount = 5;
    DataGridViewCellStyle style = 
    style.BackColor = Color.Navy;
    style.ForeColor = Color.White;
    style.Font = new Font(dataGridView1.Font, FontStyle.Bold);

    dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
    dataGridView1.Name = "dataGridView1";
    dataGridView1.Location = new Point(8, 8);
    dataGridView1.Size = new Size(500, 300);
    dataGridView1.AutoSizeRowsMode = 
    dataGridView1.ColumnHeadersBorderStyle = 
    dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
    dataGridView1.GridColor = SystemColors.ActiveBorder;
    dataGridView1.RowHeadersVisible = false;

    dataGridView1.Columns[0].Name = "Release Date";
    dataGridView1.Columns[1].Name = "Track";
    dataGridView1.Columns[1].DefaultCellStyle.Alignment = 
    dataGridView1.Columns[2].Name = "Title";
    dataGridView1.Columns[3].Name = "Artist";
    dataGridView1.Columns[4].Name = "Album";

    // Make the font italic for row four.
    dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;

    dataGridView1.BackgroundColor = Color.Honeydew;

    dataGridView1.Dock = DockStyle.Fill;

    dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
    dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing);
    addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
    deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
    ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click);
    dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);


.NET Framework
Available since 2.0
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft