DataGridViewColumn.HeaderCell Property

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets or sets the DataGridViewColumnHeaderCell that represents the column header.

[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewColumnHeaderCell HeaderCell { get; set; }

Property Value

A DataGridViewColumnHeaderCell that represents the header cell for the column.

Attributes

Examples

The following code example uses the HeaderCell property to change column header style and contents.

// Style and number columns.
private void Button8_Click(object sender,
    EventArgs args)
{
    DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.Alignment =
        DataGridViewContentAlignment.MiddleCenter;
    style.ForeColor = Color.IndianRed;
    style.BackColor = Color.Ivory;

    foreach (DataGridViewColumn column in dataGridView.Columns)
    {
        column.HeaderCell.Value = column.Index.ToString();
        column.HeaderCell.Style = style;
    }
}

Remarks

The header of a column is typically used to display a column label. Depending on the current values of the SortMode and DataGridView.SelectionMode properties, users can also click the column header to sort or select the column.

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

See also