Nasıl yapılır: Windows Forms ListView Denetimi ile Öğe Ekleme ve Kaldırma

bir Windows Forms denetimine öğe ekleme işlemi, ListView öncelikle öğeyi belirtmektir ve bu öğeye özellikler atamaktan oluşur. Liste öğelerini ekleme veya kaldırma işlemi herhangi bir zamanda yapılabilir.

Program aracılığıyla öğe eklemek için

  1. AddÖzelliğin yöntemini kullanın Items .

    // 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)
    
    

Öğeleri programlı olarak kaldırmak için

  1. RemoveAtClear Özelliğinin veya yöntemini kullanın Items . RemoveAtYöntemi tek bir öğeyi kaldırır; Clear yöntemi listedeki tüm öğeleri kaldırır.

    // 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()
    
    

Ayrıca bkz.