CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2001
    Posts
    49

    Arrow Treeview in UserControl Return Key not responding

    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?

    Thank you for your help.
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153
    1st: It's nuts that the event is getting lost.

    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
    thanx/good luck

  3. #3
    Join Date
    Sep 2001
    Posts
    49
    Thanks, you gave me an idea.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured