tags:

views:

34

answers:

2

When TreeView (WinForms) has focus pressing key selects the node whose text begins with a key character.

Is there a way to avoid this?

First thing that came to my mind was to create Control that inherits from TreeView, and override IsInputKey so that it returns false in all undesirable cases.

But it doesn't work. Is there any way to override this behavior?

A: 

I think I found one possible work around (though not elegant and not ideal)

So, I check KeyDown event, and if it happens I record selected node in one variable.

After that in AfterSelect event I actually Select that node again.

If someone has more elegant solution, it would be welcome.

Ivan
I also found that setting e.SupressKeyPress to true on KeyDown events, but it was not good solution for my application.
Ivan
A: 

For both KeyPress and KeyDown events of the TreeView (not the form) implementing

e.Handled = false;

will block the selection of the node. Moreover, these events will be fired only when the TreeView is focused already. And it will not block the whitespace key.

26071986