Hi All,

I’m using the following coding for my searching function at listview, but I facing some problem here, if I use this code I only able to search the item at column 0 for the listview. But for my case, I want to let user click on the header of the column then the user only can key in the data for that column they select, what mean is if user click on the column 0 at the header of the listview then user only can search what ever data appear at the column 0 for the listview. As well for column 1, column 2 for the listview. The following coding only allow me to search the data at column 0 even I use the select case for the column click. What mistake I have made? Can anyone give me some advice on this? Thanks.

This is my coding for the searching function at lisview:-

Private Sub ListView_Master_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView_Master.ColumnClick

Dim Search_Code As String
Dim exactMatch As Boolean
Dim mySearchText As String

Select Case e.Column
Case 0 'column one BOM ID


Case 1 'column two Cust Part # = BOM


mySearchText = Trim(InputBox("Please enter your Customer Part #", "Search Product Master Entry Data"))

'For Each itm As ListViewItem In ListView_Master.Items
For Each itm As ListViewItem In ListView_Master.Items
If exactMatch Then
If itm.Text = mySearchText Then
' an exact match was found ...
End If
mySearchText &= "*"
If itm.Text Like mySearchText Then
' a partial match was found ...
End If
End If

Case 2 'column three Child Part#A = CodeAChild Part#B = CodeB

Case 3 'column three Child Part#B = CodeB

End Select

End Sub

10 Years
Discussion Span
Last Post by Lord Soth


Try these : delete the select case parts and change the itm.Text on the ifs to a private variable (lets say iText), and put the following before "if iText = mySearch..."

if e.Column = 0 then iText = item.Text
else iText = item.SubItems[e.Column+1].Text
end if

Hope it helps.

Loren Soth

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.