DrawListViewSubItemEventArgs.ItemState Propiedad

Definición

Obtiene el estado actual del ListViewItem primario del ListViewItem.ListViewSubItem que se va a dibujar.

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

Valor de propiedad

Combinación bit a bit de valores ListViewItemStates que indican el estado actual del objeto ListViewItem primario.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la ItemState propiedad en una aplicación que proporciona un dibujo personalizado para un ListView control. En el ejemplo, un controlador para el ListView.DrawSubItem evento dibuja los valores de texto del subelemento y el texto y el fondo de los subelementos que tienen valores negativos.

Para obtener el ejemplo completo, consulte el DrawListViewSubItemEventArgs tema de referencia de información general.

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

Comentarios

Utilice esta propiedad para comprobar si el ListViewItem elemento primario del ListViewItem.ListViewSubItem que se va a dibujar está en un estado determinado. Esta propiedad solo proporciona información de estado básica sobre el elemento primario. Puede usar esta propiedad, por ejemplo, para determinar si el elemento primario está seleccionado, activado o centrado. Si necesita más información, recupere el elemento primario a través de la Item propiedad y compruebe sus propiedades directamente.

Se aplica a

Consulte también