2010-12-13 69 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(...)