DataGridViewRowPostPaintEventArgs.State Property

Definition

Gets the state of the current DataGridViewRow.

C#
public System.Windows.Forms.DataGridViewElementStates State { get; }

Property Value

A bitwise combination of DataGridViewElementStates values that specifies the state of the row.

Examples

The following code example demonstrates how to use the State property to determine whether the current row is selected. The variable, e, is of type DataGridViewRowPostPaintEventArgs. This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

C#
// Determine the foreground color.
if ((e.State & DataGridViewElementStates.Selected) ==
    DataGridViewElementStates.Selected)
{
    forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
}
else
{
    forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
}

Remarks

This property can be used to determine whether the row is frozen, read-only, or selected, among other states.

Applies to

Product Versions
.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

See also