Using Like functions for search
I am searching through my data grid view. My search variable picks data from the Cell, matches with search string and reports. This is perfect.
I need to make it work so that if use wants to search say "John", block containing "John Smith" should be matched. At the moment I have to use "John Smith" completely.Please advise how to do it. My code is shown below.
Do While vrTotalRows > vrLoopCntr
vrPickFromGrid = UCase(DataGridView1.Item(0, vrLoopCntr).Value)
If vrPickFromGrid = UCase(txtFind.Text) Then 'Found
DataGridView1.Rows(vrLoopCntr).DefaultCellStyle.BackColor = Color.CornflowerBlue
End If
vrPickFromGridC2 = UCase(DataGridView1.Item(1, vrLoopCntr).Value)
If vrPickFromGridC2 = UCase(txtFind.Text) Then 'Found
DataGridView1.Rows(vrLoopCntr).DefaultCellStyle.BackColor = Color.CornflowerBlue
End If
vrLoopCntr = vrLoo开发者_如何学PythonpCntr + 1
Loop
I suggest you use String.Contains
If vrPickFromGrid = UCase(txtFind.Text) Then
becomes :
If vrPickFromGrid.Contains(UCase(txtFind.Text)) Then
Use String.Contains(...)
.
精彩评论