I need a big help. If you open the attached file and run it. Click once on the treeview so it has focus. Now use the arrow keys and press enter key. Nothing happens.
Stop the program and open up the UserControl and change the User Control property DefaultCancel = False. Now run it and press Enter key. You will see that the debug.print statement executed in the Treeview_Keypress.
Well, it is a scaled down of the actual control we have in our program. There are other buttons on the control that has Default = True set. We have tried everything we can to get it to work. The only other option is to rewrite the whole thing and do away with the user control if we can't make use of the Enter key because of the user control property being True.
I thought if you people can help before we start talking about rewriting it. The real reason behind this is that majority of our clients are keyboard oriented, so they want to be able to select a single item (the last child, never a parent) in the treeview with the Enter key. Yes, it has to be the Enter key. It work one way but not the other way. How do I overcome that?
2nd: Try setting KeyPreview for the UserControl to True and trapping the KeyUp event (or KeyDown, Press doesn't work). Maybe you can determine if a leaf has been selected from there.
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print KeyCode & "control.down"
End Sub
Private Sub UserControl_KeyPress(KeyAscii As Integer)
Debug.Print KeyCode & "control.press"
End Sub
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
Debug.Print KeyCode & "control.up"
End Sub
I made a boolean and in the treeview gotfocus, I set it to true then in the lostfocus, set it to false
In the usercontrol_KeyUp (KeyPress doesn't work) event, test if the boolean is true then call the treeview_keypress event.
Works good in the sample code, now I am implementing it to the real control and see if there is any side effect for setting the Usercontrol.KeyPreview to True.
The changes I made in the sample program are as follows: set UserControl.KeyPreview to True then add all statements below.
Private mblnFocusOnTreeview As Boolean
Private Sub TreeView1_GotFocus()
mblnFocusOnTreeview = True
End Sub
Private Sub TreeView1_KeyPress(KeyAscii As Integer)
Debug.Print "tree" & KeyAscii
End Sub
Private Sub TreeView1_LostFocus()
mblnFocusOnTreeview = False
End Sub
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
Debug.Print "control" & KeyCode
If mblnFocusOnTreeview Then Call TreeView1_KeyPress(KeyCode)
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.