Vb.net 按键关闭事件在listview中不起作用
这是我的键控代码:Vb.net 按键关闭事件在listview中不起作用,vb.net,listview,keydown,Vb.net,Listview,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的测试时,它起作用。代码用于在listview中选择与txtFind值匹配的记录
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的测试时,它起作用。代码用于在listview中选择与txtFind值匹配的记录
提前感谢您您的代码正在运行,您只需将焦点发送到lvBranch 对于txtFind
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
如果您的listview的格式为KeyPreview=True,那么listview的按键句柄不会处理ENTER键,那么您的意思是,msgbox会工作,但是“lvBranch.FindItem…”行不工作?我认为
lvBranch.FindItemWithText(txtFind.Text,True,0,False).Selected=True
这是您的问题。@Rex:是的,先生line@LeonardDrapeza:是的,先生,它在按键事件中不工作,但在按键事件中工作。所以按键事件是用于txtFind的,对吗?您能在此行设置断点并检查txtFind.Text的值吗?它有时并没有给你期望的价值。。。