13,043,898 members (47,887 online)
Rate this:
See more:
for searching The data in listview I using : 2 Textbox, 1 button and 1 listview.

I need search more than 1 item, because i have same name and same value in my listview Columns.
This code just can search 1 item:

```Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
LviHK.MultiSelect = False
LviHK.FullRowSelect = True

Dim checkInt As Integer = FindItem(LviHK, TextBox1.Text)
If checkInt <> -1 Then
LviHK.Items(checkInt).Selected = True
LviHK.Focus()
LviHK.SelectedItems(0).EnsureVisible()
Else
End If
End Sub
Private Function FindItem(ByVal LV As ListView, ByVal TextToFind As String) As Integer
' Loop through LV’s ListViewItems.
For i As Integer = 0 To LV.Items.Count - 1
If Trim(LV.Items(i).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i)
End If
For subitem As Integer = 0 To LV.Items(i).SubItems.Count - 1
If Trim(LV.Items(i).SubItems(subitem).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i)
End If
Next
Next
Return -1
End Function```
Posted 11-Apr-13 6:05am

Rate this:

## Solution 1

Have a look at your function:
```Private Function FindItem(ByVal LV As ListView, ByVal TextToFind As String) As Integer
' Loop through LV’s ListViewItems.
For i As Integer = 0 To LV.Items.Count - 1
If Trim(LV.Items(i).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i) 'returns only 1 value but need to return more than one
End If
For subitem As Integer = 0 To LV.Items(i).SubItems.Count - 1
If Trim(LV.Items(i).SubItems(subitem).Text) = Trim(TextToFind) Then
' If found, return the row number
Return (i) 'returns only 1 value but need to return more than one
End If
Next
Next
End Function```

Use ListOf(T)[^] generic class.

```Function FindItem(ByVal LV As ListView, ByVal TextToFind As String) AS List(Of Integer)
Dim IntList As New List(Of Integer)

'inside loop

'after all
Return IntList
End ```

You need to change code to your needs.
Yazid Aura Robbani 12-Apr-13 7:10am

I've been solved with your solution
Thank you Maciej Los
Maciej Los 12-Apr-13 11:43am

You're welcome ;)

Top Experts
Last 24hrsThis month
 OriginalGriff 140 ppolymorphe 120 F-ES Sitecore 105 Sheila Pontes 95 LuxGiammi 80
 OriginalGriff 4,335 RickZeeland 1,834 ppolymorphe 1,574 F-ES Sitecore 1,553 Dave Kreskowiak 1,309

Web01 | 2.8.170713.1 | Last Updated 11 Apr 2013