在datagridview中的文本框中的列中查找部分字符串匹配 [英] Find a partial string match in column from text box in datagridview

查看:81
本文介绍了在datagridview中的文本框中的列中查找部分字符串匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据用户输入客户姓氏的文本框中的部分或完全匹配在数据网格视图中选择一行。我可以使用完全匹配但不是部分匹配。我尝试在文本框的末尾添加一个通配符,但无法使其正常工作。我的代码显示了完全匹配的作用以及我尝试使用部分匹配的代码作为下面的注释。有人可以告诉我我做错了吗?



I am trying to select a row in a datagridview based on a partial or full match from a textbox where the user enters the customer''s last name. I can make it work with a full match but not a partial match. I have tried adding a wildcard onto the end of the text box and have not been able to make it work. My code shows what works with a full match and what I have tried with the code from a partial match as a comment below it. Can someone tell me what I am doing wrong?

If StringToSearch Like (Me.TextBox1.Text) Then
'If stringToSearch Like " & (me.textbox1.text) & '"%"   
     Dim myCurrentCell As DataGridViewCell = gRow.Cells(1)
     Dim myCurrentPosition As DataGridViewCell = gRow.Cells(0)
     DataGridView1.CurrentCell = myCurrentCell
     CurrentRowIndex = DataGridView1.CurrentCell.RowIndex
     CurrentRowIndex = DataGridView1.CurrentRow.Index
     DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.LightSkyBlue
     Found = True
End If

推荐答案

使用Contains()方法。



Use the Contains() method.

If (StringToSearch.Contains(Me.TextBox1.Text)) Then


我在另一个论坛找到了解决方案。



语句:
I found the solution in another forum.

for the statement:
If StringToSearch Like (Me.TextBox1.Text) Then 

'Change to the following statment

IF Instr(StringToSearch, lcase(trim(Textbox1.Text))) <> 0 Then


这篇关于在datagridview中的文本框中的列中查找部分字符串匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆