PRB: Arrow Key Doesn't Fire Keypress Treeview/Listview Controls
ID: Q143405
|
The information in this article applies to:
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
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
- Set the Form's KeyPreview property to True.
- 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.
- 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.
Additional query words:
Keywords : kbcode kbVBp400 PrgOther VB4WIN kb32bitOnly
Version : 4.0
Platform : NT WINDOWS
Issue type : kbprb
|