开发者

Using Like functions for search

开发者 https://www.devze.com 2023-01-30 21:56 出处:网络
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 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(...).

0

精彩评论

暂无评论...
验证码 换一张
取 消