Hello,
I want to search a specific column in ListView. I've coded searching however it always defaults to search the first column, how can i specify which column to search?
Here is my code:
Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
If txtSearchThoughts.Text IsNot "" Then
'ListViewSearch.Focus()
'For i = 0 To ListViewSearch.Items.Count - 1
'If ListViewSearch.Items(i).SubItems(0).Text = txtSearchThoughts.Text Then
'ListViewSearch.Items(i).Selected = True
'End If
'Next
Dim itm As ListViewItem
Dim i As Integer
For i = 0 To ListViewSearch.Items.Count - 1
ListViewSearch.Items(i).Selected = False
ListViewSearch.Items(i).BackColor = Color.White
Next
With ListViewSearch
itm = .FindItemWithText(txtSearchThoughts.Text, False, 0, True)
If Not itm Is Nothing Then
'.TopItem = itm
.Items.Item(itm.Index).BackColor = Color.BurlyWood
.Items.Item(itm.Index).EnsureVisible()
Else
MsgBox("No Record Found!")
For i = 0 To ListViewSearch.Items.Count - 1
ListViewSearch.Items(i).Selected = False
ListViewSearch.Items(i).BackColor = Color.White
Next
.Items(0).EnsureVisible()
.Items.Item(0).BackColor = Color.BurlyWood
txtSearchThoughts.SelectionStart = 0
txtSearchThoughts.SelectionLength = Len(txtSearchThoughts.Text)
txtSearchThoughts.Focus()
End If
End With
itm = Nothing
End If
End Sub