我使用文本框和 DGV 构建了一个自动提示搜索。一切正常,除此之外,我确实想要 2 个按钮,它们提供向上或向下移动 1 行的功能。您必须知道,当我搜索时,我将那些不包含搜索字符串的行设置为.visible = false
.
理论上它应该像这样工作:
Private Sub tsbDown_Click(sender As Object, e As EventArgs) Handles tsbDown.Click
With dgvMA
If dgvMA.RowCount > 0 Then
Dim MyDesiredIndex As Integer = GetNextVisibleCell(dgvMA.CurrentRow.Index)
dgvMA.ClearSelection()
dgvMA.CurrentCell = dgvMA.Rows(MyDesiredIndex).Cells(1)
dgvMA.Rows(MyDesiredIndex).Selected = True
End If
End With
End Sub
Private Function GetNextVisibleCell(currentrow As Integer) As Integer
With dgvMA
For i = currentrow To .Rows.Count - 1
If .Rows(i).Visible = True Then
MsgBox(i & ": " & .Rows(i).Visible)
Return i
Exit For
End If
Next
Return currentrow
End With
End Function
但永远不会选择我的行。multi-select
设置为false
和。当我手动单击一行或使用键盘选择它时,所有内容都会正确打印。fullrowselect
true
我究竟做错了什么?