Click here to Skip to main content
14,324,982 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am allowing users to pick certain criteria through by checkbox in listview. I can get the listview to select checkboxed listview items, but I can not seem to unselect the ones I do not want if I accidentally select them.

Here is my code:

Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.ItemChecked

        For Each itms As ListViewItem In ListView1.CheckedItems

            If itms.Checked = True Then

                itms.Selected = True


                itms.Selected = False

            End If


    End Sub 

problem is with this code if I try to uncheck a checkbox then all of the items get unselected.

What I have tried:

I have tried using the index function to single out an individual item, but that didn't work. I used
ListView1.CheckedItems.Item(itms.Index).Selected = False
but it still didn't produce the results I was looking for.
Ramza360 8-Jan-18 14:18pm
The ListView itself was designed this way, unchecking one of any selected items will in fact uncheck them all. You can get around it by making a list of the 'other' items that are checked/selected, unselected them, uncheck this item clicked, then reselect the others.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100