While working on a community app project (you’ll hear more on this later), I needed help setting the selection (and inactive selection) on a tree view.
Just a refresher from my first ever blog post,
Explanation of Focus and Selection
Focus: Only one control or UI Element can take focus at a time. If I were to press a key on the keyboard, the keystroke can only be sent to that control with focus.
Selection: Multiple controls can have multiple items selected. List boxes can have as many or as few items selected.
Inactive Selection: When focus moves away from the list box (with selected items) to another control, those list box items are said to have inactive selection:
Active Selection: The selected list box item with focus. Hence, only one item can have Active Selection.
Suppose you have a form that consists of a button and tree view or list view with several nodes. Start with selecting one of the nodes either by clicking to tabbing/arrowing to it. When you tab away, the selection will disappear. The same will happen via code if you try to select a node. The node is actually selected, but there’s no visible indication.
To fix this, there’s a property called HideSelection. After you drop your list view or tree view onto the form, set HideSelection = False. Now, you’ll see the selection or inactive selection whether you’re selecting via code or tabbing away from the control.
Same goes for Standard Win32 Controls. For example, on a standard Win32 tree view control, you’ll need to set the TVS_SHOWSELALWAYS style bit.
And I thought I had retired this category feed. Old habits die hard. <grins>