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 場合は、コントロール内の複数の項目を一度に 1 つです。 選択することができます。それ以外の場合、falseします。true 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. この例を実行するを含むフォームに次のコードを貼り付け、ListViewという名前のオブジェクトListView1TextBoxという名前のTextBox1します。To run this example, paste the following code into a form that contains a ListView object named ListView1 and a TextBox named TextBox1. 呼び出す、InitializeListViewフォームのコンス トラクターのメソッドまたはLoadメソッド。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.

適用対象

こちらもご覧ください