Magnus Lindhe

How to turn off selection on a ListView control

In .NET Framework 4.5 the ListView control has a property called SelectionMode that determines the selection of list view items. There are three modes of operation:

  • Single - The user can select only one item at a time.
  • Multiple - The user can select multiple items without holding down a modifier key.
  • Extended - The user can select multiple consecutive items while holding down the SHIFT key.

There is however no selection mode None that disallows selection. Luckily there is another way to achieve the same behvaiour using a custom style for the ListViewItem.

The following style makes it impossible for the ListViewItem to gain focus and become selected.

    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Focusable" Value="False"/>

This solution also works for the ListBox since ListView is a dervived control.

comments powered by Disqus