ListViewItem.Selected プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ListViewItem.Selected プロパティの意味・解説 

ListViewItem.Selected プロパティ

項目が選択されているかどうかを示す値を取得または設定します

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

解説解説

項目を格納している ListView コントロールの MultiSelect プロパティtrue設定されている場合、このプロパティの値を設定すると、一連の選択された項目に項目を追加したり、これらの項目から項目を削除したできますMultiSelect プロパティfalse設定されている場合、このプロパティの値を設定して項目を選択すると、ListView コントロール内の他の選択項目が自動的にキャンセルされます。このプロパティ使用して、項目が選択されているかどうか確認したり、実行時に項目を選択できます。ListView.SelectedItems プロパティ使用すると、ListView コントロール選択されているすべての項目にアクセスできます

メモメモ

項目が選択済みとして表示されるのは、ListView コントロールフォーカス設定されているときだけです。ボタン クリックなどのユーザー アクション反応して項目を選択するには、このプロパティ設定するだけでなく、必ず Focus メソッド呼び出します。

使用例使用例

ListView.Clear メンバSelected メンバ使用する方法次のコード例示します。この例を実行するには、ListView1 という名前の ListView含まれButton1 という名前の Button下端配置されフォームに、次のコード貼り付けます。次にフォームコンストラクタまたは Loadイベント処理メソッドInitializeListView メソッド呼び出します。

Private Sub InitializeListView()

    ' Set up the inital values for the ListView and populate it.
    Me.ListView1 = New ListView
    Me.ListView1.Dock = DockStyle.Top
    Me.ListView1.Location = New System.Drawing.Point(0,
 0)
    Me.ListView1.Size = New System.Drawing.Size(292,
 130)
    Me.ListView1.View = View.Details
    Me.ListView1.FullRowSelect = True

    Dim breakfast() As String
 = New String() {"Continental
 Breakfast", "Pancakes and Sausage", _
   "Denver Omelet", "Eggs &
 Bacon", "Bagel & Cream Cheese"}

    Dim breakfastPrices() As String
 = New String() {"3.09",
 "4.09", "4.19", _
       "4.79", "2.09"}

    PopulateMenu("Breakfast", breakfast, breakfastPrices)
End Sub

Private Sub PopulateMenu(ByVal
 meal As String, _
    ByVal menuItems() As String,
 ByVal menuPrices() As String)
    Dim columnHeader1 As New
 ColumnHeader
    With columnHeader1
        .Text = meal & " Choices"
        .TextAlign = HorizontalAlignment.Left
        .Width = 146
    End With
    Dim columnHeader2 As New
 ColumnHeader
    With columnHeader2
        .Text = "Price"
        .TextAlign = HorizontalAlignment.Center
        .Width = 142
    End With
    Me.ListView1.Columns.Add(columnHeader1)
    Me.ListView1.Columns.Add(columnHeader2)

    Dim count As Integer

    For count = 0 To menuItems.Length - 1
        Dim listItem As New
 ListViewItem(menuItems(count))
        listItem.SubItems.Add(menuPrices(count))
        ListView1.Items.Add(listItem)
    Next

    ' Use the Selected property to select the first item on 
    ' the list.
    ListView1.Focus()
    ListView1.Items(0).Selected = True
End Sub


Private Sub Button1_Click(ByVal
 sender As System.Object, _
    ByVal e As System.EventArgs) Handles
 Button1.Click

    ' Create new values for the ListView, clear the list, 
    ' and repopulate it.
    Dim lunch() As String
 = New String() {"Hamburger",
 _ 
        "Grilled Cheese", "Soup
 & Salad", "Club Sandwich", "Hotdog"}

    Dim lunchPrices() As String
 = New String() {"4.09",
 "5.09", _
        "5.19", "4.79",
 "2.09"}

    ListView1.Clear()

    PopulateMenu("Lunch", lunch, lunchPrices)
    Button1.Enabled = False
End Sub
private void InitializeListView()
{
    // Set up the inital values for the ListView and populate it.
    this.ListView1 = new ListView();
    this.ListView1.Dock = DockStyle.Top;
    this.ListView1.Location = new System.Drawing.Point(0,
 0);
    this.ListView1.Size = new System.Drawing.Size(292,
 130);
    this.ListView1.View = View.Details;
    this.ListView1.FullRowSelect = true;

    string[] breakfast = new string[]{"Continental
 Breakfast", 
        "Pancakes and Sausage", "Denver Omelet", "Eggs &
 Bacon", 
        "Bagel & Cream Cheese"};

    string[] breakfastPrices = new string[]{"3.09",
 "4.09", 
        "4.19", "4.79", "2.09"};

    PopulateMenu("Breakfast", breakfast, breakfastPrices);
}

private void PopulateMenu(string
 meal, 
    string[] menuItems, string[] menuPrices)
{
    ColumnHeader columnHeader1 = new ColumnHeader();
    columnHeader1.Text = meal + " Choices";
    columnHeader1.TextAlign = HorizontalAlignment.Left;
    columnHeader1.Width = 146;

    ColumnHeader columnHeader2 = new ColumnHeader();
    columnHeader2.Text = "Price";
    columnHeader2.TextAlign = HorizontalAlignment.Center;
    columnHeader2.Width = 142;

    this.ListView1.Columns.Add(columnHeader1);
    this.ListView1.Columns.Add(columnHeader2);

    for(int count=0; count < menuItems.Length;
 count++)
    {
        ListViewItem listItem = 
            new ListViewItem(menuItems[count]);
        listItem.SubItems.Add(menuPrices[count]);
        ListView1.Items.Add(listItem);
    }

    // Use the Selected property to select the first item on 
    // the list.
    ListView1.Focus();
    ListView1.Items[0].Selected = true;
}


private void Button1_Click(System.Object sender,
 System.EventArgs e)
{
    // Create new values for the ListView, clear the list, 
    // and repopulate it.
    string[] lunch = new string[]{"Hamburger",
 "Grilled Cheese",
        "Soup & Salad", "Club Sandwich", "Hotdog"};

    string[] lunchPrices = new string[]{"4.09",
 "5.09", "5.19", 
        "4.79", "2.09"};

    ListView1.Clear();

    PopulateMenu("Lunch", lunch, lunchPrices);
    Button1.Enabled = false;
}
private:
   void InitializeListView()
   {
      // Set up the inital values for the ListView and populate it.
      this->ListView1 = gcnew ListView;
      this->ListView1->Dock = DockStyle::Top;
      this->ListView1->Location = System::Drawing::Point(
 0, 0 );
      this->ListView1->Size = System::Drawing::Size( 292,
 130 );
      this->ListView1->View = View::Details;
      this->ListView1->FullRowSelect = true;
      array<String^>^breakfast = {"Continental Breakfast","Pancakes
 and Sausage","Denver Omelet","Eggs & Bacon","Bagel
 & Cream Cheese"};
      array<String^>^breakfastPrices = {"3.09","4.09","4.19"
,"4.79","2.09"};
      PopulateMenu( "Breakfast", breakfast, breakfastPrices );
   }

   void PopulateMenu( String^ meal, array<String^>^menuItems,
 array<String^>^menuPrices )
   {
      ColumnHeader^ columnHeader1 = gcnew ColumnHeader;
      columnHeader1->Text = String::Concat( meal, " Choices" );
      columnHeader1->TextAlign = HorizontalAlignment::Left;
      columnHeader1->Width = 146;
      ColumnHeader^ columnHeader2 = gcnew ColumnHeader;
      columnHeader2->Text = "Price";
      columnHeader2->TextAlign = HorizontalAlignment::Center;
      columnHeader2->Width = 142;
      this->ListView1->Columns->Add( columnHeader1 );
      this->ListView1->Columns->Add( columnHeader2 );
      for ( int count = 0; count < menuItems->Length;
 count++ )
      {
         ListViewItem^ listItem = gcnew ListViewItem( menuItems[ count ] );
         listItem->SubItems->Add( menuPrices[ count ] );
         ListView1->Items->Add( listItem );

      }
      
      // Use the Selected property to select the first item on 
      // the list.
      ListView1->Focus();
      ListView1->Items[ 0 ]->Selected = true;
   }

   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^
 /*e*/ )
   {
      // Create new values for the ListView, clear the list, 
      // and repopulate it.
      array<String^>^lunch = {"Hamburger","Grilled Cheese","Soup
 & Salad","Club Sandwich","Hotdog"};
      array<String^>^lunchPrices = {"4.09","5.09","5.19"
,"4.79","2.09"};
      ListView1->Clear();
      PopulateMenu( "Lunch", lunch, lunchPrices );
      Button1->Enabled = false;
   }
private void InitializeListView()
{
    // Set up the inital values for the ListView and populate it.
    this.listView1 = new ListView();
    this.listView1.set_Dock(DockStyle.Top);
    this.listView1.set_Location(new System.Drawing.Point(0,
 0));
    this.listView1.set_Size(new System.Drawing.Size(292,
 130));
    this.listView1.set_View(View.Details);
    this.listView1.set_FullRowSelect(true);

    String breakfast[] = new String[] { "Continental Breakfast"
,
        "Pancakes and Sausage", "Denver Omelet", "Eggs &
 Bacon",
        "Bagel & Cream Cheese" };

    String breakfastPrices[] = new String[] { "3.09",
 "4.09", "4.19",
        "4.79", "2.09" };

    PopulateMenu("Breakfast", breakfast, breakfastPrices);
} //InitializeListView

private void PopulateMenu(String meal,String
 menuItems[],String menuPrices[])
{
    ColumnHeader columnHeader1 = new ColumnHeader();
    columnHeader1.set_Text(meal + " Choices");
    columnHeader1.set_TextAlign(HorizontalAlignment.Left);
    columnHeader1.set_Width(146);

    ColumnHeader columnHeader2 = new ColumnHeader();
    columnHeader2.set_Text("Price");
    columnHeader2.set_TextAlign(HorizontalAlignment.Center);
    columnHeader2.set_Width(142);

    this.listView1.get_Columns().Add(columnHeader1);
    this.listView1.get_Columns().Add(columnHeader2);

    for (int count = 0; count < menuItems.length;
 count++) {
        ListViewItem listItem =
            new ListViewItem((String)menuItems.get_Item(count));
        listItem.get_SubItems().Add((String)menuPrices.get_Item(count));
        listView1.get_Items().Add(listItem);
    }
    // Use the Selected property to select the first item on 
    // the list.
    listView1.Focus();
    listView1.get_Items().get_Item(0).set_Selected(true);
} //PopulateMenu

private void button1_Click(System.Object sender,
 System.EventArgs e)
{
    // Create new values for the ListView, clear the list, 
    // and repopulate it.
    String lunch[] = new String[] { "Hamburger", "Grilled
 Cheese",
        "Soup & Salad", "Club Sandwich", "Hotdog"
 };

    String lunchPrices[] = new String[] { "4.09", "5.09",
 "5.19",
        "4.79", "2.09" };

    listView1.Clear();

    PopulateMenu("Lunch", lunch, lunchPrices);
    button1.set_Enabled(false);
} //button1_Click
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ListViewItem クラス
ListViewItem メンバ
System.Windows.Forms 名前空間
ListView.SelectedItems プロパティ
ListView.SelectedIndices プロパティ


このページでは「.NET Framework クラス ライブラリ リファレンス」からListViewItem.Selected プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からListViewItem.Selected プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からListViewItem.Selected プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ListViewItem.Selected プロパティのお隣キーワード
検索ランキング

   

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



ListViewItem.Selected プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS