DataGridViewColumn.HeaderText プロパティ

定義

列のヘッダー セルのキャプション テキストを取得または設定します。

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

プロパティ値

目的のテキストの String。 既定値は、空の文字列 ("") です。

次のコード例では、 プロパティを HeaderText 使用して列ヘッダーのテキストを変更します。 このコード例は、DataGridViewColumn クラスのために提供されている大規模な例の一部です。

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

注釈

このプロパティは、列にヘッダー セルが関連付けられている場合にのみ役立ちます。 詳細については、HeaderCellCore プロパティを参照してください。

注意

行に対応するヘッダー テキスト プロパティはありません。 行ヘッダーにラベルを表示するには、イベントを DataGridView.CellPainting 処理し、 が -1 のときに独自のラベル DataGridViewCellPaintingEventArgs.ColumnIndex を描画する必要があります。

適用対象

こちらもご覧ください