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?
C# – How to select all items in a listbox on checkbox checked
.net-2.0c++listboxwinforms
Related Question
- C# – Case insensitive ‘Contains(string)’
- C# – LINQ’s Distinct() on a particular property
- C# – How to convert UTF-8 byte[] to string
- C# – How to remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning
- C# – Call one constructor from another
- C# – reason for C#’s reuse of the variable in a foreach
- C# – Try-catch speeding up the code
- C# – Entity Framework 5 Updating a Record
Best Solution
The fact is that
ListBox.Items
is a plain object collection and returns plain untyped objects, which cannot be multi-selected (by default).If you want to multi-select all items, then this will work: