DataGridViewCell.Style 属性

定义

获取或设置单元格的样式。

C#
[System.ComponentModel.Browsable(true)]
public System.Windows.Forms.DataGridViewCellStyle Style { get; set; }

属性值

DataGridViewCellStyle

与单元格关联的样式。

属性

示例

下面的代码示例演示如何使用 Style 属性获取单元格的背景色。 此示例是为 DataGridViewColumn 类提供的大型代码示例的一部分。

C#
private void CustomizeCellsInThirdColumn()
{
    int thirdColumn = 2;
    DataGridViewColumn column =
        dataGridView.Columns[thirdColumn];
    DataGridViewCell cell = new DataGridViewTextBoxCell();

    cell.Style.BackColor = Color.Wheat;
    column.CellTemplate = cell;
}

注解

DataGridView 控件使用单元格 InheritedStyle 属性指示的样式显示其单元格,该样式从类型 DataGridViewCellStyle的其他属性继承样式。 通过 Style 属性指定的样式将覆盖通过所有其他单元格样式属性指定的样式,但不一定指示导致单元格外观的所有样式。

有关详细信息,请参阅 Windows 窗体 DataGridView 控件中的单元格样式

适用于

产品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅