views:

1520

answers:

3

How do you disable additional checkbox selections/deselections without sacrificing the functionality of the ListView? I know you can call: ListView.Enabled = False, but that also disables any scrolling within it.

For example: I have a timer that starts a backup based on the Listview items that are checked. After a certain time, I don't want the end-user to be able to click on any of the checkboxes within the listview (so I have a set number of items to backup), but I do want them to be able to scroll the list while the backup is being performed. I tried this:

Private Sub clboxOptions_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles clboxOptions.ItemChecked

If backupStarted = True Then
   If e.Item.Checked = True Then
      e.Item.Checked = False
   Else
      e.Item.Checked = True
End If

But this doesn't seem to work for me. Thanks! JFV

A: 

Instead using the built-in CheckBoxes property, you could draw the check boxes yourself.

Google around and find an example of an OwnerDraw ListView. Draw the checkboxes yourself. Add a new property to your ListView (something like ReadOnly). When ReadOnly is true, draw the checkboxes as disabled and ignore the click messages.

NascarEd
A: 

You could use ObjectListView (which is a wrapper around a normal .NET ListView). It provides a callback, CheckStatePutter, which is called when the user clicks on a checkbox. In that callback, you can decide whether or not to accept the new checkbox value.

This is a recipe describing this process: How do I use checkboxes in my ObjectListView?

Grammarian
A: 

I found out what my issue was. I was using the 'ItemChecked' instead of the 'ItemCheck' Method. The below code works for me:

Private Sub clboxOptions_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clboxOptions.ItemCheck
    Try
        If backupStarted = True Then
            If e.CurrentValue <> e.NewValue Then
                e.NewValue = e.CurrentValue
            Else
                e.NewValue = e.NewValue
            End If
        End If
End Sub
JFV
Maybe this instead: If backupStarted = True Then e.NewValue = e.CurrentValue End If
Grammarian