how can i programaticaly delete the selected item (row) from a listview with 3 or more columns ?

Hi.
I make a form with a listview.
I managed to programaticaly add items on the listview but dont know how to edit or remove the selected rows.
Can anyone help me
Thx.


Answer this question

how can i programaticaly delete the selected item (row) from a listview with 3 or more columns ?

  • George Cai

    Hi,

    you can get the Objects of the listbox with SelectedItem (SelectedItems) or listbox.Items array.

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpref/html/frlrfsystemwindowsformslistboxclassitemstopic.asp

  • GoranB

    Is this code also correct

    Private Sub DeleteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteButton.Click

    Dim i As Integer
    i = ListView1.SelectedIndices.Item(0)
    ListView1.Items.Item(i).Remove()
    End Sub

    Its working fine into my app.


  • Rakesh Kumar V.V. from Pampady

    Thx man
  • kevin_estcst

    I didnt find my answer there. Can u post code

    The code must be something like this :

    ListView1.ListItems.Remove(ListView1.SelectedItem)

    This worked in vb .net 2003

    In 2005 doesnt work


  • micxba

    To remove the selected items, try this:

    For Each lvi As ListViewItem In Me.ListView1.SelectedItems< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


       Me
    .ListView1.Items.Remove(lvi)

     
    Next lvi

     



  • Rubal Jain

    If anyone can tell how to save the added items on the listview aboce on form closing that will be great.
    thx


  • Morten Dahl

    The ListView control's MultiSelect property is set to true by default. If the user selects more than one item, your code will only delete the first one. If you set ListView.MultiSelect = false, then this code is fine.



  • how can i programaticaly delete the selected item (row) from a listview with 3 or more columns ?