ListView.DrawSubItem 이벤트

정의

ListView의 자세히 보기가 그려지고 OwnerDraw 속성이 true로 설정되면 발생합니다.

public:
 event System::Windows::Forms::DrawListViewSubItemEventHandler ^ DrawSubItem;
public event System.Windows.Forms.DrawListViewSubItemEventHandler DrawSubItem;
public event System.Windows.Forms.DrawListViewSubItemEventHandler? DrawSubItem;
member this.DrawSubItem : System.Windows.Forms.DrawListViewSubItemEventHandler 
Public Custom Event DrawSubItem As DrawListViewSubItemEventHandler 

이벤트 유형

예제

다음 코드 예제에서는 이벤트 처리기의 구현을 DrawSubItem 제공합니다. 전체 예제를 참조 하세요.를 OwnerDraw 참조 항목입니다.

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

설명

이 이벤트의 모양을 사용자 지정할 수 있습니다는 ListView 소유자 그리기를 사용 하 여 제어 합니다. 발생 하는 경우에만 합니다 OwnerDraw 속성이 trueView 속성이 View.Details합니다. 소유자 그리기에 대 한 자세한 내용은 참조는 OwnerDraw 속성 참조 항목입니다.

참고

하위 항목 정보는 일반적으로 타일 보기와 세부 정보 보기에 표시되지만 타일 보기에서는 이벤트에 대한 DrawItem 처리기에 그려야 합니다.

이벤트는 DrawSubItemListView 하위 항목에 대해 발생할 수 있습니다. 이벤트를 처리 DrawItem 하여 배경과 같은 모든 하위 항목에 공통적인 요소를 그리고 이벤트를 처리 DrawSubItem 하여 텍스트 값과 같은 개별 하위 항목에 대한 요소를 그릴 수 있습니다. 두 이벤트 중 하나만 사용하여 컨트롤의 ListView 모든 항목을 그릴 수도 있지만, 이 작업은 덜 편리할 수 있습니다. 세부 정보 보기에서 열 머리글을 그리려면 이벤트를 처리 DrawColumnHeader 해야 합니다.

참고

DrawSubItem 컬렉션에 개체가 추가 Columns 되지 않은 하위 항목에는 ColumnHeader 이벤트가 발생하지 않습니다. 또한 각 ListViewItem 개체의 첫 번째 하위 항목은 부모 항목 자체를 나타내며 첫 번째 열에 표시됩니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보