Listview ( remove item ) in vb.net?

dynamic_sysop

Senior Contributor
Joined
Oct 1, 2002
Messages
1,039
Location
Ashby, Leicestershire.
Hi can someone please help me with a question on listview in visual basic.net, i have always used vb6 and to remove an item is easy in that for example.....
Dim sName as String, i as Integer
For i = 1 to listview.listitems.count
if listview.listitems(i).text = sName Then
listview.listitems.remove(i)
Exit For
End if
Next i

this would remove the item from the listview in vb6, but in .net i cant find anyway of removing an item short of if you have selected it:-\ , i make chat clients on msn-chat and use listview as the names list, therefore i cant just make it so an item is removed by clicking on it, i have to have a userparted sub and then compare the user's name with the name in the listview.
any help with this would be greatly appreciated ty:)
 
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.

Visual Basic:
    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
 
thanx m8 i have been trying to find this out for a long time now and you have fixed my problem, can i ask if there is a place that actually references these things anywhere? cuz i have a teach your self vb.net book and it's basically a waste of time:-\
 
yup, but the books dont seem to teach you anything. anyway a few things i have sussed with listview like say......
txtMain.SelectionFont = New Font(txtMain.SelectionFont, FontStyle.Italic) to set a font to itallic, but nothing shows how to change a font from say "Webdings" to "Tahoma"
 
Back
Top