I need to select all items in a ListBox when a CheckBox is clicked. Is it possible to select all items in the ListBox using a single line of code? Or will I have to loop through all items and set selected to true for each one of them?
Thanks :)
I need to select all items in a ListBox when a CheckBox is clicked. Is it possible to select all items in the ListBox using a single line of code? Or will I have to loop through all items and set selected to true for each one of them?
Thanks :)
Select All is definetly available out of the box:
I know this question is tagged with .NET 2.0 but if you have LINQ available to you in 3.5+, you can do the following:
I have seen a number of (similar) answers all which does logically the same thing, and I was baffled why yet they all dont work for me. The key is setting listbox's
SelectionMode
toSelectionMode.MultiSimple
. It doesn't work withSelectionMode.MultiExtended
. Considering to select multiple items in a listbox, you will have selection mode set to multiple mode, and mostly people go for the conventionalMultiExtended
style, this answer should help a lot. And ya not aforeach
, butfor
.You should actually do this:
OR