通过


DataGridViewRowPostPaintEventArgs.State 属性

定义

获取当前 DataGridViewRow状态。

public:
 property System::Windows::Forms::DataGridViewElementStates State { System::Windows::Forms::DataGridViewElementStates get(); };
public System.Windows.Forms.DataGridViewElementStates State { get; }
member this.State : System.Windows.Forms.DataGridViewElementStates
Public ReadOnly Property State As DataGridViewElementStates

属性值

指定行状态的值的 DataGridViewElementStates 按位组合。

示例

下面的代码示例演示如何使用 State 属性来确定是否选择了当前行。 变量 e的类型 DataGridViewRowPostPaintEventArgs。 此代码示例是 操作方法:自定义 Windows 窗体 DataGridView 控件中行的外观的大型示例的一部分。

// Determine the foreground color.
if ((e.State & DataGridViewElementStates.Selected) ==
    DataGridViewElementStates.Selected)
{
    forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
}
else
{
    forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
}
' Determine the foreground color.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
Else
    forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
End If

注解

此属性可用于确定行是冻结的、只读的还是选定的,以及其他状态。

适用于

另请参阅