When developing our desktop applications, me and Jiri needed to adjust behavior of group headers in the Better ListView control.
We discovered that making group header behavior customizable would be useful not only for us, but for other developers who utilize Better ListView as well, so we implemented this feature officially in Better ListView 2.5.0.
There are two new properties: ShowDefaultGroupHeader and GroupHeaderBehavior.
Hiding the Default Group Header
The ShowDefaultGroupHeader is initially set to true. This means that the default group (the group containing items which do not have a specific group) have its header displayed:
When ShowDefaultGroupHeader is set to false, the “Default” group header on top can be hidden:
Adjusting Group Header Behavior
The group headers have two kinds of behavior. They can be focused and can cause selection of items. Both of these functions can be invoked by keyboard and mouse.
The GroupHeaderBehavior property allows changing this behavior for keyboard and mouse separately.
By default, the property is set to BetterListViewGroupHeaderBehavior.All, so that all functions of the group header are turned on.
You may want to make group headers completely non-interactive. This can be done by setting the property to BetterListViewGroupHeaderBehavior.None.
Other values of the enum can be combined to create desired behavior.
Keyboard:
- Focus only
- Focus and select items in the group
Mouse:
- Focus
- Select items in the group
- Highligh when mouse cursor is over the group header
Use Case: Metadata Viewer
Here Better ListView is used for viewing image metadata tags:
Only one tag can be selected at a time, so clicking on a group header has no effect on selection and need not to be highlighted.
One may still need, however, to allow focusing the group header with keyboard and mouse so that it is possible to collapse/expand the group with arrow keys. The desired behavior can be set this way:
C#
[csharp gutter=”false” toolbar=”false”]listView.GroupHeaderBehavior = (BetterListViewGroupHeaderBehavior.KeyboardFocus & BetterListViewGroupHeaderBehavior.MouseFocus);[/csharp]
Visual Basic
[vb gutter=”false” toolbar=”false”]listView.GroupHeaderBehavior = (BetterListViewGroupHeaderBehavior.KeyboardFocus And BetterListViewGroupHeaderBehavior.MouseFocus)[/vb]