How to lock CheckState in CheckedListBox?

  • Thread starter Thread starter Vagabond Software
  • Start date Start date
V

Vagabond Software

I have a CheckedListBox where some of the items are checked and some are
not. I want the CheckState to be Read Only. Unfortunately, the Locked
property doesn't seem to prevent the user from changing the CheckState.

The CheckedListBox is on a Tab Control if that makes any difference. Any
help is greatly appreciated.

carl
 
You could use the ItemCheck property of the CheckedListBox control

Private Sub MyCheckList_ItemCheck(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemCheckEventArgs) Handles lstLabelTypes.ItemCheck
if e.CurrentValue=1 then
e.NewValue=1
end if
 
Shariq said:
You could use the ItemCheck property of the CheckedListBox control

Private Sub MyCheckList_ItemCheck(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemCheckEventArgs) Handles lstLabelTypes.ItemCheck
if e.CurrentValue=1 then
e.NewValue=1
end if

Thanks, that works with one caveat. The ItemCheck event fires even when
programmatically changing the CheckState. So, I also added a private bool
(checkStateLocked) that I could change when I want to alter the CheckState
programmatically. So the ItemCheck event block looks like this:

if (checkStateLocked) then
e.NewValue = e.CurrentValue;

Thanks again for your help.

Regards,

carl
 
Back
Top