tags:

views:

54

answers:

3

Say that I have a CheckedListBox with items "1", "2", "3", "4", and "5" in that order and I want to select "2", "3", and "4" by selecting "2" then holding shift and selecting "4". Is there any built-in way to achieve this with the CheckedListBox control? I found an article on how to use the SelectedIndexChanged event to get close to this behavior, but though it checks multiple items, it does not show them as selected.

http://www.windowsdevelop.com/windows-forms-general/multiple-selection-checkbox-53049.shtml

If there is an alternative control that I could use then I would be up for that as well.

+2  A: 

There might be an easier alternative, but you could use a ListView, set CheckBoxes to true, HeaderStyle to None, and View to List.

Correction:

Should have been set View to Details.

adrift
In my actual scenario, I have a large list of file names that will be the data. If I use the ListView, how do I set it to only be vertically scrollable and only have a single column of items?
Matthew Brown
Now that I think about it more, a ListBox is probably what I need. There's no reason to have checkboxes. They just need to select some files from a list. Thanks for the help though. Your answer would work for the test scenario from my original question.
Matthew Brown
Sorry, my mistake. You want to set `View` to `Details`. Assuming only a single column, you can also set the width of the Column to allow for the vertical scroll bar, getting the scroll bar width using `System.Windows.Forms.SystemInformation.VerticalScrollBarWidth`.
adrift
+1  A: 

It looks like multiple selection is not supported for the CheckedListBox control (See MSDN). It does support multiple checkboxes being checked, but not multiple items being selected (highlighted) at once.

I agree with the other answer that a ListView is probably the best way to get both checkboxes and multiple selection.

bde
:) Just seconds before me....
Gorgen
:) don't you hate that?
bde
+1  A: 

It appears that it it not possible to set see the remarks section in CheckedListBox.SelectionMode Property

For an easier alternative follow the adivice of adrift.

Gorgen