Export (0) Print
Expand All

DataGridViewCell.Style Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the style for the cell.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public DataGridViewCellStyle Style { get; set; }
/** @property */
public DataGridViewCellStyle get_Style ()

/** @property */
public void set_Style (DataGridViewCellStyle value)

public function get Style () : DataGridViewCellStyle

public function set Style (value : DataGridViewCellStyle)

Property Value

A DataGridViewCellStyle.

The DataGridView control displays its cells using the styles indicated by the cell InheritedStyle property, which inherits styles from other properties of type DataGridViewCellStyle. The styles specified through the Style property override the styles specified through all other cell-style properties, but do not necessarily indicate all the styles that contribute to the cell's appearance.

For more information, see Cell Styles in the Windows Forms DataGridView Control.

The following code example demonstrates how to use the Style property to get the background color of a cell. This example is part of a larger code example provided for the DataGridViewColumn class.

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

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft