Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

            Else

                itms.Selected = False

            End If

        Next

    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.
Posted
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900