rinat
rinat

Reputation: 167

Windows.Forms.ListView - Multiple selection in different groups

I have a ListView control with grouped items in it. My goal is to enable multiple selection only inside one group - the user should not be able to select any items except from those from the current group.
My first thought is on canceling some event (something that happens before the item is selected), but I can't find the right one.
Thanks in advance.

Upvotes: 0

Views: 689

Answers (1)

Flynn1179
Flynn1179

Reputation: 12075

Cancelling an event probably isn't the best idea; if a user tries to select something in a different group to the current selection, you really want the new item to be selected, and the selected items in the other group to be deselected.

I'd suggest responding to the ItemSelectionChanged event, and if the .IsSelected property of the event args is true, iterate through the list of items and deselect any that do not share a group with the newly selected item.

Upvotes: 1

Related Questions