ListView.MultiSelect プロパティ

定義

複数の項目を選択できるかどうかを示す値を取得または設定します。Gets or sets a value indicating whether multiple items can be selected.

public:
 property bool MultiSelect { bool get(); void set(bool value); };
public bool MultiSelect { get; set; }
member this.MultiSelect : bool with get, set
Public Property MultiSelect As Boolean

プロパティ値

コントロールの複数の項目を一度に選択できる場合は true。それ以外の場合は falsetrue if multiple items in the control can be selected at one time; otherwise, false. 既定値は、true です。The default is true.

次のコード例は、複数の項目を選択できるようにする ListView を示しています。The following code example demonstrates a ListView that allows multiple items to be selected. この例では、HideSelectionHeaderStyle のプロパティを設定する方法を示します。The example demonstrates setting the HideSelection and HeaderStyle properties. この例を実行するには、ListView1 という名前の ListView オブジェクトと TextBox1という名前の TextBox を含むフォームに次のコードを貼り付けます。To run this example, paste the following code into a form that contains a ListView object named ListView1 and a TextBox named TextBox1. フォームのコンストラクターまたは Load メソッドから InitializeListView メソッドを呼び出します。Call the InitializeListView method from the form's constructor or Load method.

// This method adds two columns to the ListView, setting the Text 
// and TextAlign, and Width properties of each ColumnHeader.  The 
// HeaderStyle property is set to NonClickable since the ColumnClick 
// event is not handled.  Finally the method adds ListViewItems and 
// SubItems to each column.
void InitializeListView()
{
   this->ListView1 = gcnew System::Windows::Forms::ListView;
   this->ListView1->BackColor = System::Drawing::SystemColors::Control;
   this->ListView1->Dock = System::Windows::Forms::DockStyle::Top;
   this->ListView1->Location = System::Drawing::Point( 0, 0 );
   this->ListView1->Name = "ListView1";
   this->ListView1->Size = System::Drawing::Size( 292, 130 );
   this->ListView1->TabIndex = 0;
   this->ListView1->View = System::Windows::Forms::View::Details;
   this->ListView1->MultiSelect = true;
   this->ListView1->HideSelection = false;
   this->ListView1->HeaderStyle = ColumnHeaderStyle::Nonclickable;
   ColumnHeader^ columnHeader1 = gcnew ColumnHeader;
   columnHeader1->Text = "Breakfast Item";
   columnHeader1->TextAlign = HorizontalAlignment::Left;
   columnHeader1->Width = 146;
   ColumnHeader^ columnHeader2 = gcnew ColumnHeader;
   columnHeader2->Text = "Price Each";
   columnHeader2->TextAlign = HorizontalAlignment::Center;
   columnHeader2->Width = 142;
   this->ListView1->Columns->Add( columnHeader1 );
   this->ListView1->Columns->Add( columnHeader2 );
   array<String^>^foodList = {"Juice","Coffee","Cereal & Milk","Fruit Plate","Toast & Jelly","Bagel & Cream Cheese"};
   array<String^>^foodPrice = {"1.09","1.09","2.19","2.49","1.49","1.49"};
   for ( int count = 0; count < foodList->Length; count++ )
   {
      ListViewItem^ listItem = gcnew ListViewItem( foodList[ count ] );
      listItem->SubItems->Add( foodPrice[ count ] );
      ListView1->Items->Add( listItem );

   }
   this->Controls->Add( ListView1 );
}
  // This method adds two columns to the ListView, setting the Text 
  // and TextAlign, and Width properties of each ColumnHeader.  The 
  // HeaderStyle property is set to NonClickable since the ColumnClick 
  // event is not handled.  Finally the method adds ListViewItems and 
  // SubItems to each column.
  private void InitializeListView()
  {
      this.ListView1 = new System.Windows.Forms.ListView();
      this.ListView1.BackColor = System.Drawing.SystemColors.Control;
      this.ListView1.Dock = System.Windows.Forms.DockStyle.Top;
      this.ListView1.Location = new System.Drawing.Point(0, 0);
      this.ListView1.Name = "ListView1";
      this.ListView1.Size = new System.Drawing.Size(292, 130);
      this.ListView1.TabIndex = 0;
      this.ListView1.View = System.Windows.Forms.View.Details;
      this.ListView1.MultiSelect = true;
      this.ListView1.HideSelection = false;
      this.ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
      
      ColumnHeader columnHeader1 = new ColumnHeader();
      columnHeader1.Text = "Breakfast Item";
      columnHeader1.TextAlign = HorizontalAlignment.Left;
      columnHeader1.Width = 146;

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

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

      string[] foodList = new string[]{"Juice", "Coffee", 
          "Cereal & Milk", "Fruit Plate", "Toast & Jelly", 
          "Bagel & Cream Cheese"};
      string[] foodPrice = new string[]{"1.09", "1.09", "2.19", 
          "2.49", "1.49", "1.49"};
      
      for(int count=0; count < foodList.Length; count++)
      {
          ListViewItem listItem = new ListViewItem(foodList[count]);
          listItem.SubItems.Add(foodPrice[count]);
          ListView1.Items.Add(listItem);
      }
      this.Controls.Add(ListView1);
  }
  
' This method adds two columns to the ListView, setting the Text 
' and TextAlign, and Width properties of each ColumnHeader.  The 
' HeaderStyle property is set to NonClickable since the ColumnClick 
' event is not handled.  Finally the method adds ListViewItems and 
' SubItems to each column.
Private Sub InitializeListView()
    Me.ListView1 = New System.Windows.Forms.ListView
    Me.ListView1.BackColor = System.Drawing.SystemColors.Control
    Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top
    Me.ListView1.Location = New System.Drawing.Point(0, 0)
    Me.ListView1.Name = "ListView1"
    Me.ListView1.Size = New System.Drawing.Size(292, 130)
    Me.ListView1.TabIndex = 0
    Me.ListView1.View = System.Windows.Forms.View.Details
    Me.ListView1.MultiSelect = True
    Me.ListView1.HideSelection = False
    ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
    Dim columnHeader1 As New ColumnHeader
    With columnHeader1
        .Text = "Breakfast Item"
        .TextAlign = HorizontalAlignment.Left
        .Width = 146
    End With
    Dim columnHeader2 As New ColumnHeader
    With columnHeader2
        .Text = "Price Each"
        .TextAlign = HorizontalAlignment.Center
        .Width = 142
    End With

    Me.ListView1.Columns.Add(columnHeader1)
    Me.ListView1.Columns.Add(columnHeader2)
    Dim foodList() As String = New String() {"Juice", "Coffee", _
        "Cereal & Milk", "Fruit Plate", "Toast & Jelly", _
        "Bagel & Cream Cheese"}
    Dim foodPrice() As String = New String() {"1.09", "1.09", _
        "2.19", "2.49", "1.49", "1.49"}
    Dim count As Integer
    For count = 0 To foodList.Length - 1
        Dim listItem As New ListViewItem(foodList(count))
        listItem.SubItems.Add(foodPrice(count))
        ListView1.Items.Add(listItem)
    Next
    Me.Controls.Add(Me.ListView1)
End Sub

注釈

MultiSelect プロパティが trueに設定されている場合、ListView コントロールで複数の項目を選択できます。When the MultiSelect property is set to true, multiple items can be selected in the ListView control. 複数の項目を選択するには、ユーザーが CTRL キーを押しながら選択する項目をクリックする必要があります。To select multiple items, the user must hold down the CTRL key while clicking the items to select. 連続する項目を選択するには、最初の項目をクリックし、SHIFT キーを押しながら選択する最後の項目をクリックします。Consecutive items can be selected by clicking the first item to select and then, while holding down the SHIFT key, clicking the last item to select. 複数選択機能を使用して、ListView コントロール内の複数の項目を選択し、選択したすべての項目に対して操作を実行できます。You can use the multiple selection feature to select multiple items in the ListView control and perform an operation on all the items selected. たとえば、ユーザーは複数の項目を選択し、選択した項目を右クリックすると、選択した項目に対して実行できる一連のタスクを表示するショートカットメニューが表示されます。For example, the user could select multiple items and then right-click a selected item to display a shortcut menu that displays a set of tasks that can be performed on the selected items.

ListView コントロールで選択されている項目を特定するには、SelectedItems プロパティを使用します。To determine which items are selected in the ListView control, use the SelectedItems property. SelectedItems プロパティを使用すると、選択した項目の一覧を含む ListView.SelectedListViewItemCollection にアクセスできます。The SelectedItems property allows you to access the ListView.SelectedListViewItemCollection that contains a list of the selected items. 項目の代わりに ListView.ListViewItemCollection のインデックス位置を指定する場合は、SelectedIndices プロパティを使用して ListView.SelectedIndexCollectionにアクセスできます。If you want the index positions in the ListView.ListViewItemCollection instead of the items, you can use the SelectedIndices property to access the ListView.SelectedIndexCollection.

ListViewで複数選択を許可しない場合でも、複数の項目を選択する方法をユーザーに提供する場合は、CheckBoxes プロパティを trueに設定してチェックボックスを表示できます。If you do not want to allow multiple selections in the ListView, yet still want to offer the user a way for multiple items to be chosen, you can display check boxes by setting the CheckBoxes property to true.

適用対象

こちらもご覧ください