Como: Adicionar e remover itens com o controle ListView do Windows Forms

O processo de adicionar um item a um Windows Forms ListView controle consiste basicamente de especificar o item e atribuindo propriedades a ele. Adicionar ou remover itens de lista pode ser feito a qualquer momento.

Para adicionar itens programaticamente

  • Use o Add método para o Items propriedade.

    ' 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);
    
    
    // Adds a new item with ImageIndex 3
    listView1.get_Items().Add("List item text", 3);
    
    

Para remover itens programaticamente

  • Use o RemoveAt ou Clear método para o Items propriedade. The RemoveAt método Remove um único item; a Clear método remove todos os itens da lista.

    ' Removes the first item in the list.
    ListView1.Items.RemoveAt(0)
    ' Clears all items:
    ListView1.Items.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.get_Items().RemoveAt(0);
    
    

Consulte também

Referência

ListView controle visão geral (Windows Forms)

ListView

Outros recursos

ListView controle (Windows Forms)