DataGridViewRowPrePaintEventArgs.State DataGridViewRowPrePaintEventArgs.State DataGridViewRowPrePaintEventArgs.State DataGridViewRowPrePaintEventArgs.State Property

定義

現在の DataGridViewRow の状態を取得します。Gets the state of the current 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 値のビットごとの組み合わせ。A bitwise combination of the DataGridViewElementStates values that specifies the state of the row.

次のコード例は、使用する方法を示します、Stateプロパティを行が選択されているかどうかを判断します。The following code example demonstrates how to use the State property to determine whether a row is selected. 行が選択されている場合、コードは、カスタムの背景を描画します。If the row is selected, the code paints a custom background. 変数、eの種類はDataGridViewRowPrePaintEventArgsします。The variable, e, is of type DataGridViewRowPrePaintEventArgs. このコード例で示されている例の一部は、方法。Windows フォームの DataGridView コントロール内の行の外観をカスタマイズします。This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Determine whether the cell should be painted
// with the custom selection background.
if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
{
    // Calculate the bounds of the row.
    Rectangle rowBounds = new Rectangle(
        this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
        this.dataGridView1.Columns.GetColumnsWidth(
            DataGridViewElementStates.Visible) -
        this.dataGridView1.HorizontalScrollingOffset + 1,
        e.RowBounds.Height);

    // Paint the custom selection background.
    using (Brush backbrush =
        new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
            this.dataGridView1.DefaultCellStyle.SelectionBackColor,
            e.InheritedRowStyle.ForeColor,
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
    {
        e.Graphics.FillRectangle(backbrush, rowBounds);
    }
}
' Determine whether the cell should be painted with the 
' custom selection background.
If (e.State And DataGridViewElementStates.Selected) = _
    DataGridViewElementStates.Selected Then

    ' Calculate the bounds of the row.
    Dim rowBounds As New Rectangle( _
        Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
        Me.dataGridView1.Columns.GetColumnsWidth( _
        DataGridViewElementStates.Visible) - _
        Me.dataGridView1.HorizontalScrollingOffset + 1, _
        e.RowBounds.Height)

    ' Paint the custom selection background.
    Dim backbrush As New _
        System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
        Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
        e.InheritedRowStyle.ForeColor, _
        System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
    Try
        e.Graphics.FillRectangle(backbrush, rowBounds)
    Finally
        backbrush.Dispose()
    End Try
End If

注釈

このプロパティは、行が固定されていること、読み取り専用、または他の状態の間で、選択したかどうかを判断するのには使用できます。This property can be used to determine whether the row is frozen, read-only, or selected, among other states.

適用対象

こちらもご覧ください