searching subitem in a listview

04-01-2003, 12:08 PM
Is it possible to do a lvwPartial find on a listview subitem. I thought I read somewhere that you can not... If that is true is there some way to get around that.


04-01-2003, 12:14 PM
You can if you use lvwSubItem for the second argument.

hrm.. maybe not. I just tried it and it appears only text can be matched partially. Also the api which is wrapped works the same. LVM_FINDITEM. I'll have to look into it.

04-01-2003, 12:55 PM
this is the line I was using:
Set itmFound = ListView1.FindItem(Text1.Text, lvwSubItem, , lvwPartial)

it is returning "nothing" in itmFound however

I am just trying to match text in this particular subitem if that helps

04-01-2003, 01:04 PM
You can only match the Text item of the Listview partially. Its a limitation of Win32. This should do the job:

Public Function LVSubitemPartialSearch(ByRef lv As ListView, ByVal lNumSubItems As Long, ByRef sMatch As String, ByRef lSubItemIndex As Long) As ListItem
Dim i As Long
Dim j As Long

If lv Is Nothing Or lNumSubItems < 1 Then Exit Function

For i = 1 To lv.ListItems.Count
For j = 1 To lNumSubItems
If lv.ListItems(i).SubItems(j) Like sMatch Then
lSubItemIndex = j
Set LVSubitemPartialSearch = lv.ListItems(i)
Exit Function
End If
Next j
Next i
End Function

And you can use it like this:

Dim li As ListItem
Dim lSubItem As Long

Set li = LVSubitemPartialSearch(ListView1, 2, "*7*", lSubItem)
If Not (li Is Nothing) Then
Debug.Print li.SubItems(lSubItem)
Debug.Print "not found"
End If

04-01-2003, 03:13 PM
thanks for the help

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum