ListViewItemStates 列挙体とは? わかりやすく解説

ListViewItemStates 列挙体

メモ : この列挙体は、.NET Framework version 2.0 で新しく追加されたものです。

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

この列挙体には、メンバ値のビットごとの組み合わせを可能にする FlagsAttribute 属性が含まれています。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<FlagsAttribute> _
Public Enumeration ListViewItemStates
Dim instance As ListViewItemStates
[FlagsAttribute] 
public enum ListViewItemStates
[FlagsAttribute] 
public enum class ListViewItemStates
/** @attribute FlagsAttribute() */ 
public enum ListViewItemStates
FlagsAttribute 
public enum ListViewItemStates
メンバメンバ
 メンバ名説明
Checked項目がチェックされています。 
Default項目が既定の状態です。 
Focused項目にフォーカスがあります。 
Grayed項目が無効です。 
Hot項目の上にマウス ポインタがあります。 
Indeterminate項目が中間状態です。 
Marked項目がマークされています。 
Selected項目が選択されています。 
ShowKeyboardCues項目にショートカット キーが表示されます。 
解説解説

この列挙体は、DrawListViewItemEventArgs.State プロパティおよび DrawListViewSubItemEventArgs.ItemState プロパティで使用されます。詳細については、ListView.DrawItem イベントおよび ListView.DrawSubItem イベントのトピックを参照してください。

使用例使用例

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

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

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

詳細については、ListView.OwnerDraw のリファレンス トピックを参照してください。

' 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
// 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:
   void listView1_DrawItem( Object^ /*sender*/, DrawListViewItemEventArgs^
 e )
   {
      if ( (e->State & ListViewItemStates::Selected) !=
 (ListViewItemStates)0 )
      {
         // Draw the background for a selected item.
         e->Graphics->FillRectangle( Brushes::Maroon, e->Bounds );
         e->DrawFocusRectangle();
      }
      else
      {
         // Draw the background for an unselected item.
         LinearGradientBrush^ myBrush = gcnew LinearGradientBrush( e->Bounds,Color::Orange,Color::Maroon,LinearGradientMode::Horizontal
 );
         try
         {
            e->Graphics->FillRectangle( myBrush, e->Bounds );
         }
         finally
         {
            if ( myBrush )
               delete (IDisposable^)myBrush;
         }
      }

      if ( listView1->View != View::Details )
      {
         e->DrawText();
      }
   }
// Draws the backgrounds for the column header row and for entire
// ListView items.
private void myListView_DrawItem(Object sender,
 DrawListViewItemEventArgs e)
{
    // Draw the background for the column header row.
    if (e.get_ItemIndex() == -1) {
        e.get_Item().set_BackColor(Color.get_Black());
        e.DrawBackground();
    }
    // Draw the background for a selected item.
    else {
        if (Convert.ToInt32((e.get_State() & ListViewItemStates.Selected))
            != 0) {
            e.get_Graphics().FillRectangle(Brushes.get_Maroon(),
                e.get_Bounds());
            e.DrawFocusRectangle();
        }
        // Draw the background for an unselected item.
        else {
            LinearGradientBrush myBrush = new LinearGradientBrush(
                e.get_Bounds(), Color.get_Orange(), Color.get_Maroon(),
                LinearGradientMode.Horizontal);
            try {
                e.get_Graphics().FillRectangle(myBrush, e.get_Bounds());
            }
            finally {
                myBrush.Dispose();
            }    
        }
    }
    // Draw the item text for views other than the Details view.
    if (!(((ListView)sender).get_View().Equals(View.Details)))
 {
        e.DrawText();
    }
} //myListView_DrawItem
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Windows.Forms 名前空間
DrawListViewItemEventArgs.State プロパティ
DrawListViewSubItemEventArgs.ItemState プロパティ
ListView.DrawItem イベント
ListView.DrawSubItem イベント
ListView クラス
ListViewItem クラス



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

ListViewItemStates 列挙体のお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



ListViewItemStates 列挙体のページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS