ListViewItemStates 列挙型

定義

ListViewItem に設定できる状態を表す定数を定義します。

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

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

フィールド

Checked 8

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

Default 32

項目が既定の状態です。

Focused 16

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

Grayed 2

この項目は無効です。

Hot 64

項目の上にマウス ポインターがあります。

Indeterminate 256

項目が中間状態です。

Marked 128

項目がマークされています。

Selected 1

項目が選択されています。

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

注釈

この列挙は、 プロパティと DrawListViewSubItemEventArgs.ItemState プロパティでDrawListViewItemEventArgs.State使用されます。 詳細については、 イベントと ListView.DrawSubItem イベントに関するページをListView.DrawItem参照してください。

適用対象

こちらもご覧ください