ListViewItemStates Enum

Definition

Defines constants that represent the possible states of a ListViewItem.

This enumeration supports a bitwise combination of its member values.

public enum class ListViewItemStates
[System.Flags]
public enum ListViewItemStates
[<System.Flags>]
type ListViewItemStates = 
Public Enum ListViewItemStates
Inheritance
ListViewItemStates
Attributes

Fields

Checked 8

The item is checked.

Default 32

The item is in its default state.

Focused 16

The item has focus.

Grayed 2

The item is disabled.

Hot 64

The item is currently under the mouse pointer.

Indeterminate 256

The item is in an indeterminate state.

Marked 128

The item is marked.

Selected 1

The item is selected.

ShowKeyboardCues 512

The item should indicate a keyboard shortcut.

Examples

The following example demonstrates how to provide custom drawing for a ListView control. The ListView control in the example has a gradient background. Subitems with negative values have a red foreground and a black background.

A handler for the ListView.DrawItem event draws the background for entire items and for the column headers row. A handler for the ListView.DrawSubItem event draws the text values and both the text and background for subitems that have negative values.

A ContextMenu component provides a way to switch between the details view and the list. In the list view, only the ListView.DrawItem event is fired. In this case, the text and background are both drawn in the ListView.DrawItem event handler.

For the complete example, see the ListView.OwnerDraw reference topic.

// Draws the backgrounds for entire ListView items.
private void listView1_DrawItem(object sender,
    DrawListViewItemEventArgs e)
{
    if ((e.State & ListViewItemStates.Selected) != 0)
    {
        // Draw the background and focus rectangle for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
        e.DrawFocusRectangle();
    }
    else
    {
        // Draw the background for an unselected item.
        using (LinearGradientBrush brush =
            new LinearGradientBrush(e.Bounds, Color.Orange,
            Color.Maroon, LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(brush, e.Bounds);
        }
    }

    // Draw the item text for views other than the Details view.
    if (listView1.View != View.Details)
    {
        e.DrawText();
    }
}
' Draws the backgrounds for entire ListView items.
Private Sub listView1_DrawItem(ByVal sender As Object, _
    ByVal e As DrawListViewItemEventArgs) _
    Handles listView1.DrawItem

    If Not (e.State And ListViewItemStates.Selected) = 0 Then

        ' Draw the background for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds)
        e.DrawFocusRectangle()

    Else

        ' Draw the background for an unselected item.
        Dim brush As New LinearGradientBrush(e.Bounds, Color.Orange, _
            Color.Maroon, LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(brush, e.Bounds)
        Finally
            brush.Dispose()
        End Try

    End If

    ' Draw the item text for views other than the Details view.
    If Not Me.listView1.View = View.Details Then
        e.DrawText()
    End If

End Sub

Remarks

This enumeration is used by the DrawListViewItemEventArgs.State and DrawListViewSubItemEventArgs.ItemState properties. For more information, see the ListView.DrawItem and ListView.DrawSubItem events.

Applies to

See also