Microsoft KB Archive/143405

= PRB: Arrow Key Doesn't Fire Keypress Treeview/Listview Controls =

Article ID: 143405

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q143405



SUMMARY
Pressing an arrow key does not fire the keypress event for the Treeview and Listview controls because they have built-in functionality for these keys. It is not obvious which event is available to determine that the selected node has changed because of this behavior.



MORE INFORMATION
The ItemClick event for the Listview control and the NodeClick for the Treeview control get fired whenever an item's selection changes, even if it changes as a result of a keystroke.

Steps to Reproduce Behavior
 Start Visual Basic and click New Project (ALT, F, N) on the File menu. Click Custom controls on the Tools menu. Inside of the Custom controls dialog box, check the "Microsoft Windows Common Controls." Then click the OK button. Place a TreeView control on the form.  Insert the following code in the Form_Load event: Private Sub Form_Load

Dim nodX As Node Set nodX = TreeView1.Nodes.Add(,, "Root", "Root") Set nodX = TreeView1.Nodes.Add("Root", 4, "Node1", "Node1") Set nodX = TreeView1.Nodes.Add("Node1", 4, "Node2", "Node2") Set nodX = TreeView1.Nodes.Add("Node2", 4, "Node3", "Node3")

End Sub   Add the following line to the TreeView1_Keydown event: Debug.Print "TreeView Keydown "; KeyCode   Add the following line to the Form_Keydown event: Debug.Print "Form Keydown "; KeyCode </li> Set the Form's KeyPreview property to True.</li> Run the program. The TreeView control should have the focus. Use the arrow keys to move around the tree. Note that the keydown events are not triggered and no text appears in the debug window.</li> Press the letter "N." Note that the node having the focus changes and you can monitor the keys in the debug window. This works correctly.</li></ol>

Keywords: kb32bitonly kbprb kbcode KB143405

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.