Question

In .NET framework, is it possible to set some of the items in the CheckedListBox as "uncheckable" ? I don't want to allow user to check the same items again and add them to a another existing list.

I hope I am clear. Thanks in advance.

Was it helpful?

Solution

I would set those items as "Indeterminate" in code, and then overwrite the "NewValue" property from the ItemCheck event when the user attempts to check/uncheck them:

public Form1()
{
    InitializeComponent();
    checkedListBox1.Items.Add("Can't check me", CheckState.Indeterminate);
}

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
    if (e.CurrentValue == CheckState.Indeterminate)
    {
        e.NewValue = CheckState.Indeterminate;
    }
}

The "Can't check me" item in the CheckedListBox can't be modified, because every time the user tries to check/uncheck it, the event handler changes it back. You don't even see the UI update accordingly.

OTHER TIPS

Matt's code is good.

Yet, why have an item in the checkedlistbox and not let it be selected?
I mean why have that item in the list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top