0
我使用文本框和DGV生成自動暗示搜索。一切工作正常,除此之外,我想要2個按鈕,提供功能去1行上下。你必須知道,在我搜索時,我將那些不包含搜索字符串的行設置爲.visible = false
。DataGridView選擇行錯誤
從理論上講它應該像這樣工作:
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
。當我手動點擊一行或用鍵盤選中時,一切都打印正確。
我在做什麼錯?