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

注釈

このプロパティを使用すると、行が固定されているか、読み取り専用であるか、選択されているかを確認できます。

適用対象

こちらもご覧ください