Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I allow the user to multi-check with the CheckedListBox through the 'shift' key?

Tags:

c#

winforms

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.

like image 987
skeletank Avatar asked Sep 30 '10 18:09

skeletank


3 Answers

Multiple selection is not supported, but i got here by search to find the CheckedItems.

The selected items refers to the items that are marked, the checked items refers to the items that are checked.

Hence use .CheckedItems property instead of .SelectedItems if you want the items with a checked checkbox.

like image 149
Christian Avatar answered Sep 17 '22 12:09

Christian


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.

like image 28
Jeff Ogata Avatar answered Sep 18 '22 12:09

Jeff Ogata


CheckedListBox

 private System.Windows.Forms.CheckedListBox LBO1;

 string mySentLst = string.Join(";", LBO1.CheckedItems.Cast<string>());
like image 21
Jenna Leaf Avatar answered Sep 17 '22 12:09

Jenna Leaf