次の方法で共有


方法: Windows フォーム ListView コントロールを使用してアイテムを追加および削除する

Windows フォーム ListView コントロールに項目を追加するプロセスは、主にアイテムを指定してプロパティを割り当てることで構成されます。 リスト アイテムの追加または削除はいつでも行うことができます。

プログラムで項目を追加するには

  1. Items プロパティの Add メソッドを使用します。

    // Adds a new item with ImageIndex 3
    listView1.Items.Add("List item text", 3);
    
    
    ' Adds a new item with ImageIndex 3
    ListView1.Items.Add("List item text", 3)
    
    

プログラムで項目を削除するには

  1. Items プロパティの RemoveAt または Clear メソッドを使用します。 RemoveAt メソッドは 1 つの項目を削除します。Clear メソッドは、リストからすべての項目を削除します。

    // Removes the first item in the list.
    listView1.Items.RemoveAt(0);
    // Clears all the items.
    listView1.Items.Clear();
    
    
    ' Removes the first item in the list.
    ListView1.Items.RemoveAt(0)
    ' Clears all items:
    ListView1.Items.Clear()
    
    

関連項目