Ms access 在ms access和treeview中捕获输入

Ms access 在ms access和treeview中捕获输入,ms-access,vba,treeview,Ms Access,Vba,Treeview,我试图在Microsoft TreeView控件中捕获[ENTER] 此代码在任何普通键上都可以正常运行,但不能输入 Private Sub xProductTreeview_KeyPress(KeyAscii As Integer) 'do something treeview can understand.. Application.Quit End Sub 现在按下键不会在回车时触发,所以尝试按下键, 借助 官方声明不正确,以下代码有效: Private Sub xProduct

我试图在Microsoft TreeView控件中捕获[ENTER]

此代码在任何普通键上都可以正常运行,但不能输入

Private Sub xProductTreeview_KeyPress(KeyAscii As Integer)
  'do something treeview can understand..
  Application.Quit
End Sub
现在按下键不会在回车时触发,所以尝试按下键, 借助 官方声明不正确,以下代码有效:

Private Sub xProductTreeview_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
  'do something treeview can understand..
  If KeyCode = 32 Then Application.Quit
  'Still, KeyCode=13 doesn't trigger nothing..
End Sub
尝试将access窗体中的KeyPreivew设置为true

编辑: 这确实有效

将KeyPreview设置为true,然后:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then MsgBox xProductTreeview.SelectedItem.Text
End Sub
唯一需要整理的是返回的值是label值,它可能是非唯一的,那么如何获取键而不是节点的文本呢

问候,, //t

keyPreview=true和

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then
    Dim nodSelected As MSComctlLib.Node
    Set nodSelected = Me.xProductTreeview.SelectedItem
    MsgBox nodSelected.Key
  end if
End Sub

啊,它可以工作,然后:Dim nodSelected作为mscomctlib.Node Set nodSelected=Me.xProductTreeview.SelectedItem MsgBox nodSelected.Key