mardi 5 septembre 2017

Make listview with checkboxes act like checkbox list

I need a checkbox list that I can add read-only items (hence using a listview so I can gray-out an item and keep a user from selecting it).

However, when I click the item, the checkbox doesn't toggle. But when I add the following code to the item click event,

Private Sub LVSubFiles_Click(sender As Object, e As EventArgs) Handles LVSubFiles.Click
        If LVSubFiles.Items(LVSubFiles.FocusedItem.Index).ForeColor <> Drawing.Color.Gray Then
            If LVSubFiles.Items(LVSubFiles.FocusedItem.Index).Checked = True Then
                LVSubFiles.Items(LVSubFiles.FocusedItem.Index).Checked = False
            Else
                LVSubFiles.Items(LVSubFiles.FocusedItem.Index).Checked = True
            End If
        End If
End Sub

But in this case when the user clicks on the checkbox rather than the item, nothing happens, as well selecting any other checkbox checks both the highlighted item and the checkbox of the new item selected.

Is there a way I can make the items act like a checkbox list? I've tried using Data Grid View, but i run into similar issues and a lot of code is based on the actions of this listview.




Aucun commentaire:

Enregistrer un commentaire