DataGridViewColumn.HeaderText DataGridViewColumn.HeaderText DataGridViewColumn.HeaderText DataGridViewColumn.HeaderText Property

定義

取得或設定資料行行首儲存格上的標題文字。Gets or sets the caption text on the column's header cell.

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,加上所要的文字。A String with the desired text. 預設為空字串 ("")。The default is an empty string ("").

範例

下列程式碼範例會使用HeaderText屬性來變更資料行標頭中的文字。The following code example uses the HeaderText property to change the text in the column header. 這個程式碼範例是針對DataGridViewColumn類別提供之較大範例的一部分。This code example is part of a larger example provided for the DataGridViewColumn class.

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

備註

只有當資料行具有相關聯的標題儲存格時,這個屬性才有用。This property is useful only when the column has an associated header cell. 如需詳細資訊,請參閱 HeaderCellCore 屬性 (Property)。For more information, see the HeaderCellCore property.

注意

沒有對應的資料列標頭文字屬性。There is no corresponding header text property for rows. 若要在資料列行首中顯示標籤DataGridView.CellPainting ,當為-1 時DataGridViewCellPaintingEventArgs.ColumnIndex ,您必須處理事件並繪製您自己的標籤。To display labels in row headers, you must handle the DataGridView.CellPainting event and paint your own labels when DataGridViewCellPaintingEventArgs.ColumnIndex is -1.

適用於

另請參閱