Disable group selection in WinForms ListView control
I have a list view control that appears in a detail view with groups enabled, but when navigating up / down the list with the keyboard, the groups act as a selectable, often behave strangely, sometimes the first entry is selected.
Is there a way to disable the selection of group items?
Additional Information
Try navigating with the up and down arrow keys in the list - you will notice that the group headings are selectable and behave differently depending on the direction of navigation. I want them to be disabled - going from the last item in a group to the first item in the next group.
Download a sample project .
I am populating the control like this:
Dim dt As DataTable = CreateData()
Dim itemcoll(3) As String
For i = 0 To dt.Rows.Count - 1
For j = 0 To dt.Columns.Count - 1
itemcoll(j) = dt.Rows(i)(j).ToString()
Next
Dim lvi As New ListViewItem(itemcoll)
ListView1.Groups.Add(New ListViewGroup(itemcoll(0).Substring(0, 1), itemcoll(0).Substring(0, 1)))
lvi.Group = ListView1.Groups(itemcoll(0).Substring(0, 1))
ListView1.Items.Add(lvi)
Next
The listview control has the following options, modified using the standard constructor:
- AutoArrange: False
- FullRowSelect: True
- HideSelection: False
- MultiSelect: False
- Sort Ascending
- View: Details
You can see above that group heading Y is selected - moving down from Microsoft selects Yahoo! And the group heading scrolls down and selects Yahoo! only.
Better ListView and Better ListView Express offer this functionality out of the box:
betterListView.GroupHeaderBehavior = BetterListViewGroupHeaderBehavior.None;
You can read more about extended support for groups in the Documentation .