Home » VB.NetRSS

CheckedListBox SelectionMode in VS2008

It's a disappointment that the VS2008 CheckedListBox does not allow multiple selection. This was a shortcoming in VS2005 that we hoped would be corrected in the VS2008 edition. Since the Windows Forms CheckedListBox control extends the ListBox control, can somebody tell us the reason that the CheckedListBox control cannot accept multiple selection.

 

4 Answers Found

 

Answer 1

I have just come to use this same functionality in a project and have run in to the same problem. I see it when using VS to statically add the control  to a form - it comes up with an error when you set the SelectionMode property to anything other than None or One. But the documentation implies that it can be done:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.aspx

It says:

"The user can place a check mark by one or more items"

and then goes in to detail about how to access the collection of checked items which again implies it can be done. I am hoping that this is just a restriction/bug in the VS IDE rather than .Net.

I am going to create one programatically at runtime and see whether it lets me do this. Will report back later when I have tested.
 

Answer 2

OK. Hopefully I'm not spouting anything too obvious here, but the documentation is completely inconsistent.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.selectionmode.aspx

Thiis page says that checkedlistbox  controls can only have a selection  mode of None or One. To quote:

"For CheckedListBox objects, multiple  selection is not supported. You can set the mode to one item or no items."


But the main CheckedListBox documentation page says:

"This control  presents a list of items that the user can navigate by using the keyboard or the scrollbar on the right side of the control. The user can place a check mark by one or more items and the checked items can be navigated with the CheckedListBox..::.CheckedItemCollection and CheckedListBox..::.CheckedIndexCollection."


So, come on Microsoft, which one is it? Can a checkedlistbox be used for multi-selections or not?


However, there is some good news. The functionality doesn't follow the documentation. If you set the CheckedListBox's selectionmode  property to "One" (default), it lets you multi-select anyway! Of course, this is effectively "undocumented" behaviour which could be "fixed" in a future update of the .Net framework, but for now it works.
 

Answer 3

You have misunderstood the meaning of item selection  in the CheckedListBox control. Selection refers to whether an item is selected, i.e. highlighted. Multi-selection refers to whether multiple  items can be selected (i.e. highlighted) at one time. The CheckedListBox control  does not allow this type of multi-selection.

Whether or not an item is "checked" is a completely separate issue. The CheckedListBox stores the check state of each item, regardless of whether that item is "selected" or not. As you have stated, multiple items can be checked at one time, even though the control does not allow multi-selection.
 

Answer 4

Hi!

Is there any way to limit the CheckedListBox to only allowing one item checked?

I like the way it's compact and would like to use it in my application.  When an item is checked, I want to get its index and uncheck the other items in the CheckedBoxList.

Thanks for any help!

Mechi

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter