Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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:)

  • *Experts*
Posted

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • Leaders
Posted
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:-\

  • Leaders
Posted

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"

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...