I'm using VS 2008 C# Express edition here.
Try to use a CheckedListBox, which I think is just a fancy ListBox.
In designmode I can set the property
SelectionMode :
None (? rather strange for what I think is a list of checkboxes)

When I select one of the last two options I get a messagebox telling me: "Property value is not valid".
When I want to do this programmatically with checkedListBox1.SelectionMode = SelectionMode.MultiSimple; it compiles but I get an ArgumentException.

What am I doing wrong?(Perhaps forgot to set another property?)
Because else I don't see the need for a bunch of checkboxes and you are only allowed to select one of them.

Recommended Answers

All 6 Replies

CheckListBox is subclassed from ListBox. The SelectionMode is valid in the ListBox control, but only None and Single in the CheckListBox. It is not a true error! But, the programmer should have overridden the property and used a subset, or just a bool to allow selection or not.

Multi select is not valid due to the way the internal check on click method works with the SelectionMode.

They obviously needed to keep it because they wanted to let the None to be allowed...
// Jerry

Thank you both very much for the answers.
But I still don't see the logic in it.
I can imagine a ListBox in which you can select nothing(None). Just showing the user some items...
I cannot imagine a list with checkboxes in which you can only select nothing or only one item. I thought that was the whole purpose of check boxes: choose as much as you like!
Arrgh MS and his infinite wisdom...

EDIT: Will mark the thread as solved. The problem isn't...

Final thought :
A checkbox is used as a radiobutton here.
They better would have called it that way : a RadioListBox.
Now it's like watching a Mickey Mouse movie and thinking it's Donald Duck.

ah but then you'd expect the bits to be circles not squares :P

There is a difference between CheckedItems and SelectedItems.
As it is already a checked list box, you don't have to specify multiple checking mode.
But you can select only zero or one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.