DataGridViewColumn.HeaderCell Proprietà

Definizione

Ottiene o imposta l'oggetto DataGridViewColumnHeaderCell che rappresenta l'intestazione della colonna.

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; }
[<System.ComponentModel.Browsable(false)>]
member this.HeaderCell : System.Windows.Forms.DataGridViewColumnHeaderCell with get, set
Public Property HeaderCell As DataGridViewColumnHeaderCell

Valore della proprietà

DataGridViewColumnHeaderCell

Oggetto DataGridViewColumnHeaderCell che rappresenta la cella di intestazione della colonna.

Attributi

Esempio

Nell'esempio di codice seguente viene utilizzata la HeaderCell proprietà per modificare lo stile e il contenuto dell'intestazione di colonna.

// 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

Commenti

L'intestazione di una colonna viene in genere usata per visualizzare un'etichetta di colonna. A seconda dei valori correnti delle SortMode proprietà e DataGridView.SelectionMode , gli utenti possono anche fare clic sull'intestazione di colonna per ordinare o selezionare la colonna.

Si applica a

Vedi anche