I have a treeview on a form and it is causing a lot of grief. The treeview
has the focus. I press enter to expand the treeview and it does but then
the focus shifts to the next tabstop instead of staying in the treeview.
Secondly, none of the Key events seem to fire for the treeview either. I am
trying to catch vbKeyEnter on KeyPress to process the DblClick event. Any
ideas or suggestions?
Can you use the NodeClick event instead?

Signature
Scott McDaniel
CS Computer Software
www.thedatabaseplace.net
> I have a treeview on a form and it is causing a lot of grief. The treeview
> has the focus. I press enter to expand the treeview and it does but then
> the focus shifts to the next tabstop instead of staying in the treeview.
> Secondly, none of the Key events seem to fire for the treeview either. I am
> trying to catch vbKeyEnter on KeyPress to process the DblClick event. Any
> ideas or suggestions?
Hi Scott,
That seems a problem; for the focus problem, a workaround could be in the
Form_KeyDown event capture the Enter key, and enable Form's timer control,
in the timer event, reset the focus back to the treeview control. Remember
to set Form's KeyPreview to be true.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Me.ActiveControl.Name = "TreeView1" And 13 = KeyCode Then
Me.TimerInterval = 100
End If
End Sub
Private Sub Form_Timer()
TreeView1.SetFocus
Me.TimerInterval = 0
End Sub
For capturing vbKeyEnter, we need to capture it in form's keydown event,
since it seems the treeview control has some built-in code to process
vbKeyEnter and we are unable to capture it in treeview's keydown event. The
code is similar:
If Me.ActiveControl.Name = "TreeView1" And 13 = KeyCode Then
'your code
End If
Note: 13 stands for vbkeyenter.
Please feel free to reply to the threads if you have any questions or
concerns.
Sincerely,
Alick Ye, MCSD
Product Support Services
Microsoft Corporation
Get Secure! - <www.microsoft.com/security>
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Scott Rymer" <me@work.com>
| Subject: TreeView problems
[quoted text clipped - 7 lines]
| trying to catch vbKeyEnter on KeyPress to process the DblClick event. Any
| ideas or suggestions?