ListView Remve Item By Text

CroddZ
09-06-2003, 10:53 AM
hi, i want to remove an item from the listview control by the text and not the index, is there a way 2 do this?

thanks

zak2zak
09-06-2003, 11:00 AM
May be this helps...
U have to loop thru to find the List..

Private Sub RemoveList(sSearch As String)
Dim i As Long
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Text = sSearch Then
ListView1.RemoveItem i
Exit For
End If
Next i
End Sub

Val
09-06-2003, 11:03 AM
One way is to loop through all items by using For Each or For and when you find the text you need, remove the item and exit loop. The following code is not tested, but generally should work:

Function ListViewFindItem(ByRef ListViewCtl As ListView, ByVal ItemText As String) As Integer
Dim Itm As ListItem

For Each Itm In ListViewCtl
If Itm.Text = ItemText Then
ListViewFindItem = Itm.Index
Exit For
End If
Next
End Function

Sub cmdRemoveByText_Click()
Dim iItm As Integer

iItm = ListViewFindItem(ListView1, txtFind.Text)

If iItm Then
ListView1.ListItems.Remove iItm
Else
MsgBox "Couldn't find the specified item", vbInformation
End If
End Sub

CroddZ
09-06-2003, 11:04 AM
yeah, that works, thanks!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum