Override default behavior of SPACE key in .net WinForms ListView

Posted by Axarydax on Stack Overflow See other posts from Stack Overflow or by Axarydax
Published on 2010-03-31T09:51:43Z Indexed on 2010/03/31 9:53 UTC
Read the original article Hit count: 485

Filed under:
|
|
|
|

Hello, I'd like to implement some custom behavior of Space key in a ListView. Basically I'd like to toggle selected status of the item under cursor - that should be fairly simple

this.FocusedItem.Selected = !this.FocusedItem.Selected;

but alas, it also does the default action, which is to select the focused item. This way I am unable to 'unselect' the focused item. I've looked for similar problems and they suggest using PreviewKeyDown event, in which I would process the key and disallow the ListView to do its default action. But the PreviewKeyDown event argument has no "handled" property, so I cannot 'eat' this key.

© Stack Overflow or respective owner

Related posts about winforms

Related posts about c#