Skip to content

How to add multiple keystrokes to a TreeView node? #3589

Answered by tznind
Andras-Csanyi asked this question in Q&A
Discussion options

You must be logged in to vote

Here is an example of using the KeyPress event to perform different actions in a TreeView<FileSystemInfo>.

            // Prevent selecting many objects at once
            tv.MultiSelect = false;
            // Disable normal activation key
            tv.ObjectActivationKey = Key.Null;

            tv.KeyPress += (e) =>
            {

                // Use 'as' your class here or do conditional checks
                var o = tv.SelectedObject as FileSystemInfo;

                if (o == null)
                {
                    return;
                }

                if (e.KeyEvent.Key == Key.A)
                {
                    e.Handled = true;
                    MessageBox.Q…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Andras-Csanyi
Comment options

@tznind
Comment options

Answer selected by Andras-Csanyi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants