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 th开发者_开发百科ere any way to override this behavior?
Set the e.Handled = true;
in both keyup
& keypress
events.
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.
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.
精彩评论