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

属性值

具有所需文本的 StringA 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 属性。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.

适用于

另请参阅