2

这是我的keydown代码:

 If e.KeyCode = Keys.Enter Then
        'find the item to be selected
        lvBranch.FindItemWithText(txtFind.Text, True, 0, False).Selected = True 
    End If

当我按 enter 时,它不起作用,但是当我按 enter 进行 msgbox 之类的测试时,它起作用了。该代码用于在列表视图中选择与 txtFind 的值匹配的记录。

先感谢您

4

2 回答 2

2

您的代码正在运行,您只需将焦点发送到lvBranch

此代码应在txtFind的KeyDown事件中

If e.KeyCode = Keys.Enter Then
    Dim Result As ListViewItem = lvBranch.FindItemWithText(txtFind.Text, True, 0, False)
    If (Not Result Is Nothing) Then
        lvBranch.Focus()
        Result.Selected = True
    End If
End If
于 2013-09-19T06:16:58.510 回答
0

如果您的列表视图采用 KeyPreview = True 的形式,则您的 ListView 的 KeyDown 句柄不会处理 ENTER 键

于 2020-05-08T21:34:27.190 回答