Hi all,
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.
Hi all,
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.
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.
CheckedListBox... oh man how much do I hate this control. I'd advise you to rethink which control you are using. This thing should almost not be a Control. I wish they'd not included it in the final build of .net. It's just missing some basic things that other controls have.