catch在ms-access和treeview中输入

时间:2011-08-12 13:20:49

标签: ms-access vba treeview

我正在尝试在Microsoft TreeView控件中捕获[ENTER]。

此代码在任何普通密钥上运行正常,但不能输入。

Private Sub xProductTreeview_KeyPress(KeyAscii As Integer)
  'do something treeview can understand..
  Application.Quit
End Sub

现在按键不会在ENTER上触发,所以尝试KeyDown, 在http://www.pcreview.co.uk/forums/here-syntax-treeview-keydown-t3810664.html的帮助下 官方声明不正确,以下代码有效:

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-form中的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-value,它可能是非唯一的,那么如何获取Key而不是节点的Text?

的问候, //吨

1 个答案:

答案 0 :(得分:0)

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