Lock CheckedState in CheckedListBox?

VagabondSW

Regular
Joined
Feb 19, 2005
Messages
66
I have a CheckedListBox that has some items already checked, while other items are not. This entire CheckedListBox should be Read Only. Unfortunately, the Locked property does not seem to produce that effect.

Any ideas on locking the CheckedState of a CheckedListBox?
 
Read up on the Locked property. It is design-time only and prevents a control being moved or resized by drag-and-drop in the designer.
Visual Basic:
    Private checkAllowed As Boolean = False

    Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
        If Not Me.checkAllowed Then
            e.NewValue = e.CurrentValue
        End If
    End Sub
Whenever you want to check or uncheck an item programmatically, you have to set the checkAllowed variable to True first, and then back to False afterwards.
 
Back
Top