View previous topic :: View next topic |
Author |
Message |
JohnSummit
Joined: 10 Apr 2008 Posts: 32
|
Posted: Thu Jun 25, 2009 7:08 am Post subject: KeyDown event for left and right arrow keys? |
|
|
I don't get any notifications when pressing the left and right keys. I do get notifications for the up and down keys.
I have multiple top-level items without children. I would like to have the up/down keys select the top-level items/ The left/right keys should be sent to my form so i can act on the selected tree item.
I am handling the virtualTreeSearchResults_KeyDown event. |
|
Back to top |
|
|
JohnSummit
Joined: 10 Apr 2008 Posts: 32
|
Posted: Thu Jun 25, 2009 7:12 am Post subject: |
|
|
To clarify: I do get the left/right arrow key events when no items exist in the tree. Once items are in the tree, the tree or form does not pass on the key down event.
I did try to do a this.KeyPreview = true; in the form constructor and handle the KeyDown event for the form but no event triggered. So it seems the form is to blame. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jun 25, 2009 8:59 am Post subject: |
|
|
Arrow and tab keys are special (because they are used for navigation between controls) and are not passed to the KeyDown event. To handle arrow keys for a control you have override the ProcessCmdKey method. Since Virtual Tree handles a number of special navigation keys like arrow keys it overrides this method. The overridden method in turn calls methods ProcessLeftCmdKey, ProcessRightCmdKey etc to handle the different keys.
If you want to handle the arrow keys differently you need to derive a new control from Virtual Tree and override the ProcessLeftCmdKey and ProcessRightCmdKey methods eg.
Code: | class MyTree : VirtualTree
{
protected override bool ProcessLeftCmdKey(System.Windows.Forms.Keys modifiers)
{
return base.ProcessLeftCmdKey(modifiers);
}
} |
Note that if you want the default Virtual Tree behaviour (in addition to your own) you will need to call the base class method. _________________ Infralution Support |
|
Back to top |
|
|
|