2010-12-13 66 views
0

我正在通過我的數據網格視圖進行搜索。我的搜索變量從單元中選取數據,與搜索字符串和報告匹配。太棒了。
我需要使其工作,以便如果使用要搜索說「約翰」,應該匹配包含「約翰史密斯」的塊。目前我必須完全使用「John Smith」。使用Like功能進行搜索

請告訴如何去做。我的代碼如下所示。

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 = vrLoopCntr + 1 
     Loop 
+0

唉 - 用於你的代碼風格VB6寫了這一切。現在你所做的大部分事情都是倒退的。 – 2010-12-13 16:48:25

+0

你有什麼建議使它成爲vb.net代碼? – 2010-12-13 16:51:07

回答

0

我建議你使用String.Contains

If vrPickFromGrid = UCase(txtFind.Text) Then 

變爲:

If vrPickFromGrid.Contains(UCase(txtFind.Text)) Then 
+0

謝謝這個作品.............. – 2010-12-13 16:52:38

0

使用String.Contains(...)