How to disable a checkbox in a checkedlistbox?

Subodh Bansal picture Subodh Bansal · Dec 6, 2010 · Viewed 41.7k times · Source

I have some items in a CheckedListBox, I want to disable the CheckBox of first item in it.
i.e. I want to disable the first item in the CheckedListBox, because I want to tell the user visually that option is not available.

Answer

Mick Bruno picture Mick Bruno · Aug 5, 2013

Combining 2 of the above partial answers worked great for me. Add your items to the list with:

myCheckedListBox.Items.Add(myItem, myState);

Where myState is CheckState.Indeterminate for items that should be disabled. Then add an event handler to keep those items from being changed:

myCheckedListBox.ItemCheck += (s, e) => { if (e.CurrentValue == CheckState.Indeterminate) e.NewValue = CheckState.Indeterminate; };

This does not allow you to use 'Indeterminate' in this list for its normal purpose but it does give a look very similar to what one would expect for a disabled item and it provides the correct behavior!