我有一些带有一些数据的DataGridView,我想“做一些事情”如果文本框中的字符串(例如,Jon)是Jon或JON或者jon或者......我的代码:
For Each dr As DataGridViewRow In DataGridView1.Rows
If dr.Cells(1).Value = TextBox1.Text Then
'Do some thing
End If
Next
答案 0 :(得分:0)
只需使用UCASE:
For Each dr As DataGridViewRow In DataGridView1.Rows
If UCASE(dr.Cells(1).Value) = UCase(TextBox1.Text) Then
'Do some thing
End If
Next
答案 1 :(得分:0)
您需要对String.Equals
方法使用重载,如下所示:
dr.Cells(1).Value.Equals(TextBox1.Text, StringComparison.CurrentCultureIgnoreCase)
还有其他选项,例如使用Invariant Culture。您需要哪一个取决于您的具体情况。
答案 2 :(得分:0)
与此类似的问题是answered here。
您可以使用String.Compare
方法:
String.Compare(String strA, String strB, Boolean ignoreCase)
对ignoreCase
参数传递true以执行不区分大小写的比较。
If String.Compare(TextBox1.Text, "a", true) = 0 then
' Do something
End If