How to lock CheckState in CheckedListBox?

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
 
G

Guest

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
 
V

Vagabond Software

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top