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.

- 385
- 1
- 4
- 12
11 Answers
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!

- 1,373
- 15
- 13
-
Having just tried the same thing, note that with this event handler, as written, you cannot programmatically re-enable a 'disabled' checkbox once you have disabled it -- the ItemCheck event fires, sees the existing Indeterminate state and overrides you. In most cases, you need an additional boolean check to determine whether the change in state was user-initiated or programmatic. Of course, how you protect that boolean from race conditions is an exercise for the reader... – jimbobmcgee Aug 03 '16 at 15:36
Though this post is pretty old, the last added answer has been submitted in April this year,
and I hope this will help someone.
I was after something similar : a checked list box that behaves like
a lot of installers, which offer a list of options where some features are required and
thus are both checked and disabled.
Thanks to this post (Can I use a DrawItem event handler with a CheckedListBox?)
I managed to do that, subclassing a CheckedListBox
control.
As the OP in the linked post states, in the CheckedListBox
control the OnDrawItem
event is never fired,
so subclassing is necessary.
It's very basic, but it works.
This is what it looks like (the CheckBox
above is for comparison) :
NOTE: the disabled item is really disabled : clicking on it has no effects whatsoever (as far as I can tell).
And this is the code :
public class CheckedListBoxDisabledItems : CheckedListBox {
private List<string> _checkedAndDisabledItems = new List<string>();
private List<int> _checkedAndDisabledIndexes = new List<int>();
public void CheckAndDisable(string item) {
_checkedAndDisabledItems.Add(item);
this.Refresh();
}
public void CheckAndDisable(int index) {
_checkedAndDisabledIndexes.Add(index);
this.Refresh();
}
protected override void OnDrawItem(DrawItemEventArgs e) {
string s = Items[e.Index].ToString();
if (_checkedAndDisabledItems.Contains(s) || _checkedAndDisabledIndexes.Contains(e.Index)) {
System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedDisabled;
Size glyphSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state);
CheckBoxRenderer.DrawCheckBox(
e.Graphics,
new Point(e.Bounds.X + 1, e.Bounds.Y + 1), // add one pixel to align the check gliph properly
new Rectangle(
new Point(e.Bounds.X + glyphSize.Width + 3, e.Bounds.Y), // add three pixels to align text properly
new Size(e.Bounds.Width - glyphSize.Width, e.Bounds.Height)),
s,
this.Font,
TextFormatFlags.Left, // text is centered by default
false,
state);
}
else {
base.OnDrawItem(e);
}
}
public void ClearDisabledItems() {
_checkedAndDisabledIndexes.Clear();
_checkedAndDisabledItems.Clear();
this.Refresh();
}
}
Use it like this:
checkedListBox.Items.Add("Larry");
checkedListBox.Items.Add("Curly");
checkedListBox.Items.Add("Moe");
// these lines are equivalent
checkedListBox.CheckAndDisable("Larry");
checkedListBox.CheckAndDisable(0);
Hope this can help someone.

- 1,228
- 10
- 17
-
Thanks, it worked like a charm! Anyway it generates a problem when viewing the preview of a form containing the custom control you've defined: it generates an InvalidArgumentException: "Value of '0' is not valid for 'index'. You should add something like that at the beginning of the OnDrawItem() method: if (Items.Count < e.Index + 1) { return; } – Alessandro Martinelli Apr 05 '23 at 14:49
Disabling items isn't a great idea, the user will have no good feedback that click the check box won't have any effect. You cannot use custom drawing to make it obvious. Best thing to do is to simply omit the item.
You can however easily defeat the user with the ItemCheck event:
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) {
if (e.Index == 0) e.NewValue = e.CurrentValue;
}

- 922,412
- 146
- 1,693
- 2,536
-
3thnx, but i want to tell the user visually that the option is not available – Subodh Bansal Dec 06 '10 at 17:06
-
1"cannot use custom drawing" -- not true, but it would be somewhat difficult. It would be easier to custom draw the *text* as disabled, *and* use the disabling code provided here. – Jon Seigel Dec 06 '10 at 17:07
-
1Re-implementing the custom drawing defeats the point of using a CheckedListBox, might as well use a ListBox. As stated, the simple way to make it obvious that the option isn't available is to remove it from the Items collection. – Hans Passant Dec 06 '10 at 17:11
-
As with my comment in http://stackoverflow.com/questions/4368618/how-to-disable-a-checkbox-in-a-checkedlistbox#comment64869753_18048205, the ItemCheck event will intercept any attempts to change the check-state, including attempts to 're-enable' the checkbox. Additional checks are needed to overcome this. – jimbobmcgee Aug 03 '16 at 15:37
-
Hmm, no, that ItemCheck event handler I posted most definitely prevents the check state of the first item from being changed. Try it. – Hans Passant Aug 03 '16 at 15:50
To disable any particular item use following:
checkedListBox1.SetItemCheckState(0, CheckState.Indeterminate);
SetItemCheckState
takes index of item and CheckState
Enum
Indeterminate is used to show shaded appearance

- 1,468
- 1
- 15
- 19
-
2This does show a greyed appearance, but does not prevent the user from checking the item (I guess this can be done by implementing a listener) – personne3000 Nov 22 '14 at 14:03
I know it has been a while, but I found this in my search for a list box and thought I would add it to the discussion.
If you have a listbox and want to disable all of the checkboxes so they cannot be clicked, but not disable the control so the user can still scroll etc. you can do this:
listbox.SelectionMode = SelectionMode.None

- 226
- 3
- 8
The CheckedListBox will not work in this way. CheckedListBox.Items is a collection of strings so they cannot be "disabled" as such.
Here are some discussions about possible solutions that might help you: here and here.

- 4,771
- 3
- 25
- 26
This works for me:
checkedListBox1.SelectionMode = SelectionMode.None;
Which means no items can be selected
None: No items can be selected.
For more info, you can check it here: SelectionMode Enumeration.

- 8,604
- 6
- 46
- 57
The solution is to use the event ItemChecking
:
_myCheckedListBox.ItemChecking += (s, e) => e.Cancel = true;
This will cancel all the checking on every item, but you can always do more refined solution but testing the current .SelectedItem

- 3,318
- 22
- 47
Here's how I did it in a helpdesk application I wrote:
First, I made it so the check box was greyed out as I added it to the list during form load:
private void frmMain_Load(object sender, EventArgs e)
{
List<string> grpList = new List<string>();
ADSI objADSI = new ADSI();
grpList = objADSI.fetchGroups();
foreach (string group in grpList)
{
if (group == "SpecificGroupName")
{
chkLst.Items.Add(group, CheckState.Indeterminate);
}
else
{
chkLst.Items.Add(group);
}
}
Then I used an event so that when clicked it ensures it stays clicked:
private void chkLst_SelectedIndexChanged(object sender, EventArgs e)
{
if (chkLst.SelectedItem.ToString() == "SpecificGroupName")
{
chkLst.SetItemCheckState(chkLst.SelectedIndex, CheckState.Indeterminate);
}
}
The idea here is that on my form it's set so that the box checks on item click/select. This way I could kill two birds with one stone. I could keep this event from causing problems when the item is first checked and added during form load. Plus making it check on select allows me to use this event instead of the item checked event. Ultimately the idea is to keep it from messing up during the load.
You'll also notice that it doesn't matter what the index number is, that variable is unknown because in my app it's grabbing a list of groups from AD that exist in a specific OU.
As to whether this is a good idea or not, that's dependent on the situation. I have another app where the item to disable is dependent on another setting. In this app I just want the helpdesk to see that this group is required so they don't go removing them from it.

- 2,926
- 12
- 55
- 93
Try Below Code:
Private Sub CheckedListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseUp
If (Condition) Then
Me.CheckedListBox1.SelectedIndex = -1
End If
End Sub

- 800
- 7
- 8
I think an alternative solution, is using Telerik
components.
A RadListControl
can give you that option:

- 16,580
- 5
- 54
- 111