DataGridViewColumn.HeaderCell DataGridViewColumn.HeaderCell DataGridViewColumn.HeaderCell DataGridViewColumn.HeaderCell Property

定义

获取或设置表示列标题的 DataGridViewColumnHeaderCellGets or sets the DataGridViewColumnHeaderCell that represents the column header.

public:
 property System::Windows::Forms::DataGridViewColumnHeaderCell ^ HeaderCell { System::Windows::Forms::DataGridViewColumnHeaderCell ^ get(); void set(System::Windows::Forms::DataGridViewColumnHeaderCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewColumnHeaderCell HeaderCell { get; set; }
member this.HeaderCell : System.Windows.Forms.DataGridViewColumnHeaderCell with get, set
Public Property HeaderCell As DataGridViewColumnHeaderCell

属性值

示例

下面的代码示例使用HeaderCell属性更改列标题样式和内容。The following code example uses the HeaderCell property to change column header style and contents.

// Style and number columns.
void Button8_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
   DataGridViewCellStyle^ style = gcnew DataGridViewCellStyle;
   style->Alignment = DataGridViewContentAlignment::MiddleCenter;
   style->ForeColor = Color::IndianRed;
   style->BackColor = Color::Ivory;
   IEnumerator^ myEnum1 = dataGridView->Columns->GetEnumerator();
   while ( myEnum1->MoveNext() )
   {
      DataGridViewColumn^ column = safe_cast<DataGridViewColumn^>(myEnum1->Current);
      column->HeaderCell->Value = column->Index.ToString();
      column->HeaderCell->Style = style;
   }
}


// 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;
    }
}
' Style and number columns.
Private Sub Button8_Click(ByVal sender As Object, _
    ByVal args As EventArgs) Handles Button8.Click

    Dim style As DataGridViewCellStyle = _
        New DataGridViewCellStyle()
    style.Alignment = _
        DataGridViewContentAlignment.MiddleCenter
    style.ForeColor = Color.IndianRed
    style.BackColor = Color.Ivory

    For Each column As DataGridViewColumn _
        In dataGridView.Columns

        column.HeaderCell.Value = _
            column.Index.ToString
        column.HeaderCell.Style = style
    Next
End Sub

注解

列标题通常用于显示列标签。The header of a column is typically used to display a column label. 根据SortModeDataGridView.SelectionMode属性的当前值,用户还可以单击列标题对列进行排序或选择。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.

适用于

另请参阅