使用此代码,我可以找到我指定的单元格值的确切位置,
Dim value As String = "apple"
Dim _DisplayText_ As String = ""
Dim _row_ As Integer = 0 : Dim _col_ As Integer = 0
For i As Integer = 0 To Me.DataGridView.ColumnCount - 1
For j As Integer = 0 To Me.DataGridView.RowCount - 1
If Me.DataGridView.Rows(j).Cells(i).Value = value Then
_DisplayText_ = Me.DataGridView.Rows(j).Cells(i).Tag
_row_ = j
_col_ = i
Exit For
End If
Next
Next
有没有办法不使用这个嵌套循环?想象一下,如果 datagridview 的行是数千个数据......那将是 soooo slooowww。
有类似的内置函数吗?
msgbox(dtg.findrow("apple"))
msgbox(dtg.findcol("apple"))
编辑
我修改了我的循环并将其更改为这个,
Dim value As String = "apple"
Dim _DisplayText_ As String = ""
Dim _col_ As String = "colFruits"
Dim _row_ As Integer = 0 : Dim _col_ As Integer = 0
For i As Integer = 0 To Me.DataGridView.RowCount - 1
If Me.DataGridView.Rows(j).Cells(_col_).Value = value Then
_DisplayText_ = Me.DataGridView.Rows(j).Cells(_col_).Tag
_row_ = j
_col_ = i
Exit For
End If
Next