Search code examples
c#winformscheckedlistbox

CheckedListBox allowing only one item to be checked


In my CheckedListBox app I want to allow only a single item to be checked.

I have these properties already set

checkOnClick = true;
SelectionMode = One;

Any advise will be appreciated


Solution

  • uncheck all other items in ItemCheck event as below :

    private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) {
          for (int ix = 0; ix < checkedListBox1.Items.Count; ++ix)
            if (ix != e.Index) checkedListBox1.SetItemChecked(ix, false);
        }