DataGridViewCell.Style 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置单元格的样式。
public:
 property System::Windows::Forms::DataGridViewCellStyle ^ Style { System::Windows::Forms::DataGridViewCellStyle ^ get(); void set(System::Windows::Forms::DataGridViewCellStyle ^ value); };[System.ComponentModel.Browsable(true)]
public System.Windows.Forms.DataGridViewCellStyle Style { get; set; }[<System.ComponentModel.Browsable(true)>]
member this.Style : System.Windows.Forms.DataGridViewCellStyle with get, setPublic Property Style As DataGridViewCellStyle属性值
与单元格关联的样式。
- 属性
示例
下面的代码示例演示如何使用 Style 属性获取单元格的背景色。 此示例是为 DataGridViewColumn 类提供的大型代码示例的一部分。
void CustomizeCellsInThirdColumn()
{
   int thirdColumn = 2;
   DataGridViewColumn^ column = dataGridView->Columns[ thirdColumn ];
   DataGridViewCell^ cell = gcnew DataGridViewTextBoxCell;
   cell->Style->BackColor = Color::Wheat;
   column->CellTemplate = cell;
}
private void CustomizeCellsInThirdColumn()
{
    int thirdColumn = 2;
    DataGridViewColumn column =
        dataGridView.Columns[thirdColumn];
    DataGridViewCell cell = new DataGridViewTextBoxCell();
    cell.Style.BackColor = Color.Wheat;
    column.CellTemplate = cell;
}
Private Sub CustomizeCellsInThirdColumn()
    Dim thirdColumn As Integer = 2
    Dim column As DataGridViewColumn = _
        dataGridView.Columns(thirdColumn)
    Dim cell As DataGridViewCell = _
        New DataGridViewTextBoxCell()
    cell.Style.BackColor = Color.Wheat
    column.CellTemplate = cell
End Sub
注解
该 DataGridView 控件使用单元格 InheritedStyle 属性指示的样式显示其单元格,该样式从类型 DataGridViewCellStyle的其他属性继承样式。 通过 Style 属性指定的样式将覆盖通过所有其他单元格样式属性指定的样式,但不一定指示导致单元格外观的所有样式。
有关详细信息,请参阅 Windows 窗体 DataGridView 控件中的单元格样式。