DrawListViewSubItemEventArgs.ItemState 속성

정의

그릴 ListViewItem의 부모 ListViewItem.ListViewSubItem에 대한 현재 상태를 가져옵니다.

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

속성 값

부모 ListViewItemStates의 현재 상태를 나타내는 ListViewItem 값의 비트 조합입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ItemState 속성에 대 한 사용자 지정 그리기 기능을 제공 하는 애플리케이션에는 ListView 컨트롤입니다. 예에 대 한 처리기를 ListView.DrawSubItem 이벤트 하위 항목 텍스트 값 및 텍스트와 음수 값이 있는 하위 항목의 배경을 그립니다.

전체 예제를 참조 하세요.를 DrawListViewSubItemEventArgs 개요 항목을 참조 합니다.

// Draws subitem text and applies content-based formatting.
private void listView1_DrawSubItem(object sender,
    DrawListViewSubItemEventArgs e)
{
    TextFormatFlags flags = TextFormatFlags.Left;

    using (StringFormat sf = new StringFormat())
    {
        // Store the column text alignment, letting it default
        // to Left if it has not been set to Center or Right.
        switch (e.Header.TextAlign)
        {
            case HorizontalAlignment.Center:
                sf.Alignment = StringAlignment.Center;
                flags = TextFormatFlags.HorizontalCenter;
                break;
            case HorizontalAlignment.Right:
                sf.Alignment = StringAlignment.Far;
                flags = TextFormatFlags.Right;
                break;
        }

        // Draw the text and background for a subitem with a 
        // negative value. 
        double subItemValue;
        if (e.ColumnIndex > 0 && Double.TryParse(
            e.SubItem.Text, NumberStyles.Currency,
            NumberFormatInfo.CurrentInfo, out subItemValue) &&
            subItemValue < 0)
        {
            // Unless the item is selected, draw the standard 
            // background to make it stand out from the gradient.
            if ((e.ItemState & ListViewItemStates.Selected) == 0)
            {
                e.DrawBackground();
            }

            // Draw the subitem text in red to highlight it. 
            e.Graphics.DrawString(e.SubItem.Text,
                listView1.Font, Brushes.Red, e.Bounds, sf);

            return;
        }

        // Draw normal text for a subitem with a nonnegative 
        // or nonnumerical value.
        e.DrawText(flags);
    }
}
' Draws subitem text and applies content-based formatting.
Private Sub listView1_DrawSubItem(ByVal sender As Object, _
    ByVal e As DrawListViewSubItemEventArgs) _
    Handles listView1.DrawSubItem

    Dim flags As TextFormatFlags = TextFormatFlags.Left

    Dim sf As New StringFormat()
    Try

        ' Store the column text alignment, letting it default
        ' to Left if it has not been set to Center or Right.
        Select Case e.Header.TextAlign
            Case HorizontalAlignment.Center
                sf.Alignment = StringAlignment.Center
                flags = TextFormatFlags.HorizontalCenter
            Case HorizontalAlignment.Right
                sf.Alignment = StringAlignment.Far
                flags = TextFormatFlags.Right
        End Select

        ' Draw the text and background for a subitem with a 
        ' negative value. 
        Dim subItemValue As Double
        If e.ColumnIndex > 0 AndAlso _
            Double.TryParse(e.SubItem.Text, NumberStyles.Currency, _
            NumberFormatInfo.CurrentInfo, subItemValue) AndAlso _
            subItemValue < 0 Then

            ' Unless the item is selected, draw the standard 
            ' background to make it stand out from the gradient.
            If (e.ItemState And ListViewItemStates.Selected) = 0 Then
                e.DrawBackground()
            End If

            ' Draw the subitem text in red to highlight it. 
            e.Graphics.DrawString(e.SubItem.Text, _
                Me.listView1.Font, Brushes.Red, e.Bounds, sf)

            Return

        End If

        ' Draw normal text for a subitem with a nonnegative 
        ' or nonnumerical value.
        e.DrawText(flags)

    Finally
        sf.Dispose()
    End Try

End Sub

설명

이 속성을 사용 하 여 확인 여부를 ListViewItem 의 부모는 ListViewItem.ListViewSubItem 그릴 상태인 특정 합니다. 이 속성은 부모 항목에 대 한 기본 상태 정보를 제공 합니다. 예를 들어,이 속성을를 사용 하 여 부모 항목 선택, 옵션을 선택 또는 초점을 맞춘 결정할 수 있습니다. 자세히를 알아야 하는 경우 검색을 통해 부모 항목을 Item 속성 및 해당 속성을 직접 확인 합니다.

적용 대상

추가 정보