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 屬性 (Property)。

注意

資料列沒有對應的標頭文字屬性。 若要在資料列標頭中顯示標籤,您必須在 為 -1 時 DataGridViewCellPaintingEventArgs.ColumnIndex 處理 DataGridView.CellPainting 事件並繪製您自己的標籤。

適用於

另請參閱