DataGridViewColumn.HeaderText 属性

定义

获取或设置列标题单元格的标题文本。

C#
public string HeaderText { get; set; }

属性值

具有所需文本的 String。 默认值为空字符串("")。

示例

下面的代码示例使用 HeaderText 属性更改列标题中的文本。 此代码示例是为 DataGridViewColumn 类提供的一个更大示例的一部分。

C#
// 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());
    }
}

注解

仅当列具有关联的标题单元格时,此属性才有用。 有关更多信息,请参见 HeaderCellCore 属性。

备注

行没有相应的标头文本属性。 若要在行标题中显示标签,必须在 为 -1 时DataGridViewCellPaintingEventArgs.ColumnIndex处理DataGridView.CellPainting事件并绘制自己的标签。

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅