Cómo: Agregar y quitar elementos con el control ListView de Windows Forms

Actualización: noviembre 2007

El proceso de agregar un elemento a un control ListView de formularios Windows Forms consiste básicamente en especificar el elemento y asignarle propiedades. Puede agregar o quitar elementos de la lista en cualquier momento.

Para agregar elementos mediante programación

  • Utilice el método Add de la propiedad 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);
    
    
    // Adds a new item with ImageIndex 3
    listView1.get_Items().Add("List item text", 3);
    
    

Para quitar elementos mediante programación

  • Utilice el método RemoveAt o Clear de la propiedad Items. El método RemoveAt quita un solo elemento; el método Clear quita todos los elementos de la 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);
    
    

Vea también

Referencia

Información general del control ListView (Formularios Windows Forms)

ListView

Otros recursos

ListView (Control, formularios Windows Forms)