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

'MsgBox(e.Column)

Case 1 'column two Cust Part # = BOM

MsgBox(e.Column)

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 ...
MsgBox("Exact")
End If
Else
mySearchText &= "*"
If itm.Text Like mySearchText Then
' a partial match was found ...
MsgBox("Partial")
'ListView_Master.Select()
'ListView_Master.Focus()
End If
End If
Next

Case 2 'column three Child Part#A = CodeAChild Part#B = CodeB
MsgBox(e.Column)

Case 3 'column three Child Part#B = CodeB
MsgBox(e.Column)

End Select

End Sub

Hi,

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.