Language

ListViewItemStates 列挙型

定義

ListViewItemの可能な状態を表す定数を定義します。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

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

フィールド

名前 値 説明
Selected 1

項目は選択されます。

Grayed 2

項目が無効になっています。

Checked 8

項目がチェックされます。

Focused 16

項目にフォーカスがあります。

Default 32

項目は既定の状態です。

Hot 64

現在、項目はマウス ポインターの下にあります。

Marked 128

項目がマークされます。

Indeterminate 256

アイテムが不確定な状態です。

ShowKeyboardCues 512

項目はキーボード ショートカットを示す必要があります。

例

次の例では、 ListView コントロールにカスタム描画を提供する方法を示します。 この例の ListView コントロールにはグラデーションの背景があります。 負の値を持つサブ項目は、赤い前景と黒い背景を持ちます。

ListView.DrawItem イベントのハンドラーは、項目全体と列ヘッダー行の背景を描画します。 ListView.DrawSubItem イベントのハンドラーは、負の値を持つサブ項目のテキスト値とテキストと背景の両方を描画します。

ContextMenu コンポーネントは、詳細ビューとリストを切り替える方法を提供します。 リスト ビューでは、 ListView.DrawItem イベントのみが発生します。 この場合、テキストと背景の両方が ListView.DrawItem イベント ハンドラーに描画されます。

完全な例については、 ListView.OwnerDraw リファレンス トピックを参照してください。

// 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.State プロパティと DrawListViewSubItemEventArgs.ItemState プロパティで使用されます。 詳細については、イベントの ListView.DrawItem と ListView.DrawSubItem を参照してください。

適用対象

こちらもご覧ください