我正在做的搜索结果在我的系统,但它说:错误的搜索数据网格
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
我只能输入1位后,我删除或者进入另一个数字它会弹出错误。
这里我的代码:
Try
For row As Integer = 0 To dgv_room.Rows.Count
If dgv_room.Rows(row).Cells(0).Value.ToString.Substring(0, tbx_search.Text.Length) = tbx_search.Text Then
dgv_room.Rows(row).Selected = True
Exit For
End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
我试了一下,我现在可以输入更多的digts,但选择的行仍然在顶部,当我使用退格时,它再次弹出。 – 2012-08-12 08:57:08
好吧,'.Cells(0)'中的数据是否包含您需要搜索的数据?如果是这样,那么你应该能够删除你的代码中的'.Substring(0,tbx_search.Text)'部分。 – XN16 2012-08-12 09:01:02
对不起,但我仍然没有得到它,如果他们什么都没有找到,我怎么能回到它?我不能使用退后的空间。此代码是搜索 – 2012-08-12 09:05:51