ListViewItemStates 枚举

定义

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

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

public enum class ListViewItemStates
[System.Flags]
public enum ListViewItemStates
type ListViewItemStates = 
Public Enum ListViewItemStates
继承
ListViewItemStates
属性

字段

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.

示例

下面的示例演示如何为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);
        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

注解

此枚举由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.

适用于

另请参阅