DataGridViewColumn.HeaderText Właściwość

Definicja

Pobiera lub ustawia tekst podpis w komórce nagłówka kolumny.

public:
 property System::String ^ HeaderText { System::String ^ get(); void set(System::String ^ value); };
public string HeaderText { get; set; }
member this.HeaderText : string with get, set
Public Property HeaderText As String

Wartość właściwości

Element String z żądanym tekstem. Wartością domyślną jest ciąg pusty ("").

Przykłady

Poniższy przykład kodu używa HeaderText właściwości , aby zmienić tekst w nagłówku kolumny. Ten przykład kodu jest częścią większego przykładu podanego DataGridViewColumn dla klasy.

// Change the text in the column header.
void Button9_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
   IEnumerator^ myEnum2 = dataGridView->Columns->GetEnumerator();
   while ( myEnum2->MoveNext() )
   {
      DataGridViewColumn^ column = safe_cast<DataGridViewColumn^>(myEnum2->Current);
      column->HeaderText = String::Concat( L"Column ", column->Index.ToString() );
   }
}
// Change the text in the column header.
private void Button9_Click(object sender,
    EventArgs args)
{
    foreach (DataGridViewColumn column in dataGridView.Columns)
    {

        column.HeaderText = String.Concat("Column ",
            column.Index.ToString());
    }
}
' Change the text in the column header.
Private Sub Button9_Click(ByVal sender As Object, _
    ByVal args As EventArgs) Handles Button9.Click

    For Each column As DataGridViewColumn _
        In dataGridView.Columns

        column.HeaderText = String.Concat("Column ", _
            column.Index.ToString)
    Next
End Sub

Uwagi

Ta właściwość jest przydatna tylko wtedy, gdy kolumna ma skojarzona komórkę nagłówka. Aby uzyskać więcej informacji, zobacz HeaderCellCore właściwość .

Uwaga

Nie ma odpowiedniej właściwości tekstowej nagłówka dla wierszy. Aby wyświetlić etykiety w nagłówkach wierszy, musisz obsługiwać DataGridView.CellPainting zdarzenie i malować własne etykiety, gdy DataGridViewCellPaintingEventArgs.ColumnIndex ma wartość -1.

Dotyczy

Zobacz też