ListView.MultiSelect ListView.MultiSelect ListView.MultiSelect ListView.MultiSelect Property

定義

複数の項目を選択できるかどうかを示す値を取得または設定します。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. この例では、 HideSelectionプロパティHeaderStyleとプロパティを設定する方法を示します。The example demonstrates setting the HideSelection and HeaderStyle properties. この例を実行するにはListView 、という名前ListView1のオブジェクトとという名前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メソッドからメソッドを呼び出します。InitializeListViewCall 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

注釈

プロパティがMultiSelecttrue設定されている場合、 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.

適用対象

こちらもご覧ください