答案 0 :(得分:5)
答案 1 :(得分:0)
使用knslyr的回复发布完整的代码段,但在原始代码的上下文中,仅针对子孙后代:
Try
' Search (case insensitive) for the first occurrence of the given string
Dim foundCell As DataGridViewCell = (
From row As DataGridViewRow In dgvMembers.Rows,
cell As DataGridViewCell In row.Cells
Where cell.Value.ToString.ToUpper.Contains(searchText)
Select cell
).First
' If we have a match, select it
If foundCell IsNot Nothing Then
' Select the cell if we have a match
dgvMembers.CurrentCell = foundCell
WriteMessage("String '{0}' found.", searchText)
Else
' No cell found. Whoops.
WriteMessage("String '{0}' NOT found.", searchText)
End If
Catch ex As Exception
' An exception probably means the New row was reached. So, no dice.
WriteMessage("String '{0}' NOT found.", searchText)
End Try