ListViewItemStates ListViewItemStates ListViewItemStates ListViewItemStates Enum


定义表示 ListViewItem 的可能状态的常数。Defines constants that represent the possible states of a ListViewItem.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class ListViewItemStates
public enum ListViewItemStates
type ListViewItemStates = 
Public Enum ListViewItemStates


Checked Checked Checked Checked 8

已选中该项。The item is checked.

Default Default Default Default 32

该项处于它的默认状态。The item is in its default state.

Focused Focused Focused Focused 16

该项有焦点。The item has focus.

Grayed Grayed Grayed Grayed 2

该项已禁用。The item is disabled.

Hot Hot Hot Hot 64

该项当前位于鼠标指针下。The item is currently under the mouse pointer.

Indeterminate Indeterminate Indeterminate Indeterminate 256

该项处于不确定的状态。The item is in an indeterminate state.

Marked Marked Marked Marked 128

该项已被标记。The item is marked.

Selected Selected Selected Selected 1

该项已选定。The item is selected.

ShowKeyboardCues ShowKeyboardCues ShowKeyboardCues ShowKeyboardCues 512

该项应指示键盘快捷键。The item should indicate a keyboard shortcut.


下面的示例演示如何提供有关自定义绘图ListView控件。The following example demonstrates how to provide custom drawing for a ListView control. ListView在示例中的控件具有渐变背景。The ListView control in the example has a gradient background. 子项并将负值有红色的前景色和背景为黑色。Subitems with negative values have a red foreground and a black background.

处理程序ListView.DrawItem事件绘制整个项和列标题行的背景。A handler for the ListView.DrawItem event draws the background for entire items and for the column headers row. 处理程序ListView.DrawSubItem事件绘制的文本值以及文本和背景具有负值的子项。A handler for the ListView.DrawSubItem event draws the text values and both the text and background for subitems that have negative values.

一个ContextMenu组件提供了一种方法的详细信息视图和列表之间进行切换。A ContextMenu component provides a way to switch between the details view and the list. 在列表视图中,仅ListView.DrawItem触发事件。In the list view, only the ListView.DrawItem event is fired. 在这种情况下,文本和背景均在ListView.DrawItem事件处理程序。In this case, the text and background are both drawn in the ListView.DrawItem event handler.

有关完整示例,请参阅ListView.OwnerDraw参考主题。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);
        // 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)
' 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)


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

    End If

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

End Sub


此枚举由DrawListViewItemEventArgs.StateDrawListViewSubItemEventArgs.ItemState属性。This enumeration is used by the DrawListViewItemEventArgs.State and DrawListViewSubItemEventArgs.ItemState properties. 有关详细信息,请参阅ListView.DrawItemListView.DrawSubItem事件。For more information, see the ListView.DrawItem and ListView.DrawSubItem events.