DataGridViewRowPrePaintEventArgs.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형식입니다 DataGridViewRowPrePaintEventArgs. 이 코드 예제는 방법: Windows Forms DataGridView 컨트롤에서 행의 모양 사용자 지정에 제공된 더 큰 예제의 일부입니다.

// 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

설명

이 속성은 행이 다른 상태 중에서 고정, 읽기 전용 또는 선택되었는지 여부를 확인하는 데 사용할 수 있습니다.

적용 대상

추가 정보