Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Re: Listview ( remove item ) in vb.net?

 

split from http://www.xtremedotnettalk.com/showthread.php?t=42557, please don't reply to posts more than 30 days old, consider starting a new thread if it is a new problem. PD

 

 

ListView.Items.Remove removes a ListItem from the list by

passing that item to the method, so you can use a For Each loop

to loop through all the items and remove the offending ones.

 

Here lvw is a ListView, sName is the text of the item you want to

delete, and li is the ListItem class to loop with.

 

   Dim li As ListViewItem
   Dim sName As String

   For Each li In lvw.Items
     If li.Text = sName Then
       lvw.Items.Remove(li)
       ' If you only want to remove one item with that Text 
       ' you can put an Exit For right here
     End If
   Next

 

Hi, is there another way to delete an item in listview similar to the code you gave, but this time deleting a selected item like:

 

Dim li As ListViewItem
   Dim sName As String

   For Each li In lvw.Items
     If [u]li.selectedItem.Index[/u] Then
       lvw.Items.Remove(li)
       ' If you only want to remove one item with that Text 
       ' you can put an Exit For right here
     End If
   Next

the underlined code is the one i want to get.

Edited by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...