How to change which item is “outlined” in a ListBox without changing the selection?

Posted by Timwi on Stack Overflow See other posts from Stack Overflow or by Timwi
Published on 2011-01-06T02:49:44Z Indexed on 2011/01/06 2:53 UTC
Read the original article Hit count: 412

Filed under:
|
|

How do you change which item is “outlined” in a ListBox? See the following screenshot for clarification:

Screenshot demonstrating what I mean by “outlined” item as opposed to “selected” item

Background: I want to have a standard multi-select listbox that works normally. Unfortunately, the Windows Forms ListBox (with SelectionMode.MultiExtended) is not fully functional. The missing functionality is that it doesn’t let you select a disjoint set of items by using Ctrl+Arrow keys and Ctrl+Space. (Try it in Windows Explorer to see how it’s supposed to work.) I am trying to subclass ListBox and add this missing functionality. To this end, I intend to respond to Ctrl+Arrow keys in the OnKeyDown protected method, but in order to do so, I need to be able to move the outline without changing the set of selected items. How do I do that?

© Stack Overflow or respective owner

Related posts about winforms

Related posts about listbox