Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
搜索Datagridview Vb.net_Vb.net_Search_Datagridview - Fatal编程技术网

搜索Datagridview Vb.net

搜索Datagridview Vb.net,vb.net,search,datagridview,Vb.net,Search,Datagridview,我一直在Vb.net中创建Datagridview搜索 我有一个绑定到绑定源的DataGridView。它包含以下数据: 123456, 213926, 285643, 395687, 我到处都搜索过,但我只找到了绑定源的过滤方法或find方法。 filter方法删除剩余的行&find方法查找精确的字符串 我在DataGridView中找到了一个查找文本的方法,但该搜索在DataGridView列的任何位置都找到了字符串,就像用户键入2一样,然后它将首先选择包含2的行,例如123456 我想创

我一直在Vb.net中创建Datagridview搜索

我有一个绑定到绑定源的
DataGridView
。它包含以下数据:

123456,
213926,
285643,
395687,
我到处都搜索过,但我只找到了绑定源的过滤方法或find方法。 filter方法删除剩余的行&find方法查找精确的字符串

我在
DataGridView
中找到了一个查找文本的方法,但该搜索在
DataGridView
列的任何位置都找到了字符串,就像用户键入2一样,然后它将首先选择包含2的行,例如123456

我想创建一个搜索引擎,它应该按照从开始到结束的顺序查找字母。
如果用户按2,则搜索应转到以2开头的单元格,如213926

事情解决了,弗兰克。非常感谢。 这是我给其他人的完整代码

Dim Found As Boolean = False
Dim StringToSearch As String = ""
Dim ValueToSearchFor As String = Me.TextBox1.Text.Trim.ToLower
Dim CurrentRowIndex As Integer = 0
Try
  If dgvDishonourReceipts.Rows.Count = 0 Then
         CurrentRowIndex = 0
  Else
         CurrentRowIndex = dgvDishonourReceipts.CurrentRow.Index + 1
  End If
  If CurrentRowIndex > dgvDishonourReceipts.Rows.Count Then
         CurrentRowIndex = dgvDishonourReceipts.Rows.Count - 1
  End If
  If dgvDishonourReceipts.Rows.Count > 0 Then
       For Each gRow As DataGridViewRow In dgvDishonourReceipts.Rows
          StringToSearch = gRow.Cells(4).Value.ToString.Trim.ToLower
          If InStr(1, StringToSearch, LCase(Trim(TextBox1.Text)), vbTextCompare) = 1 Then
            Dim myCurrentCell As DataGridViewCell = gRow.Cells(4)
            Dim myCurrentPosition As DataGridViewCell = gRow.Cells(0)
            dgvDishonourReceipts.CurrentCell = myCurrentCell
            CurrentRowIndex = dgvDishonourReceipts.CurrentRow.Index
            Found = True
          End If
          If Found Then Exit For
        Next
  End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try

看看这个问题:@FrankvanPuffelen亲爱的Frank!这个解决方案还可以找到整个字符串。我在前面提到过,我想从一开始就用部分字符串按顺序搜索。这部分代码处理:
如果InStr(1,dgvString,strFind,vbTextCompare)0
。如果InStr(1,dgvString,strFind,vbTextCompare)=1,则您需要将其更改为
,这表明字符串是从第一个字符开始找到的。我刚刚注意到,我复制的答案已被删除,可能是出于良好的原因。你先给我们看看你试过什么,这样我们就可以开始工作了。这是我的代码。从建议的链接
Dim toSearch As String=TextBox1.Text.ToString Dim colNum As Integer=13 Dim res=Dset.Tables(“si_ReceiptMaster”).AsEnumerable.Where(Function(x)x.Item(colNum).ToString()=toSearch.ToArray res Dim curRow中的每个项目作为Integer=Dset.Tables(“si_ReceiptMaster”).Rows.IndexOf(Item)dgvDishonourReceipts.Rows(curRow).DefaultCellStyle.BackColor=Color.Yellow Next