Jes*_*mes 5 vb.net search datagridview row winforms
我已经做了很多寻找此答案的工作,但没有一个能够帮助我。.Focus()自其他网站建议以来,我尝试使用甚至查看是否适用,但事实并非如此。我只想要DataGridViewHistoryData。
跳到所选行。它当然会这样做,但是当有足够的项目填充网格时,它不会滚动到它。网格上可能缺少一个参数吗?
这是我的代码:
Private Sub HistorySearch_TextChanged(sender As Object, e As EventArgs) Handles HistorySearch.TextChanged
Try
If HistorySearch.Text.ToString <> "" Then
For Each HistoryRow As DataGridViewRow In HistoryData.Rows
HistoryData.ClearSelection()
For Each HistoryCell As DataGridViewCell In HistoryRow.Cells
If HistoryCell.Value.ToString.StartsWith(HistorySearch.Text.ToString) Then
HistoryRow.Selected = True
Dim i As Integer = HistoryData.CurrentRow.Index()
Else
HistoryRow.Selected = False
End If
If HistoryCell.Value.ToString.Contains(HistorySearch.Text.ToString) Then
HistoryRow.Selected = True
Dim i As Integer = HistoryData.CurrentRow.Index()
Return
Else
HistoryRow.Selected = False
End If
Next
Next
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
如果我正确理解了您的问题,则可以DataGridView使用以下任一选项滚动到特定的行:
CurrentCell
如果设置CurrentCell,DataGridView则选择指定的单元格并滚动以使该单元格可见。
例如,选择最后一行并滚动到它:
'use suitable index, 10 is just for example
DataGridView1.CurrentCell = dataGridView1.Rows(10).Cells(0)
Run Code Online (Sandbox Code Playgroud)
FirstDisplayedScrollingRowIndex
您还可以设置FirstDisplayedScrollingRowIndex滚动到特定行,但不选择该行:
例如,仅滚动到第十行:
'use suitable index, 10 is just for example
DataGridView1.FirstDisplayedScrollingRowIndex = 10
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9474 次 |
| 最近记录: |