Select All Items in a CheckedListBox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Select All Items in a CheckedListBox

Post by dank42 »

Hi,

What is the easiest way to select all the items in a checked list box?

I wanted a checkbox called "select all" and when checked -eq $true, all the items in the list box are checked.

Cheers.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Select All Items in a CheckedListBox

Post by jvierra »

Code: Select all

# check all items
(0..($checkedlistbox1.Items.Count -1)) | %{ $checkedlistbox1.SetItemChecked($_,$true)}
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Select All Items in a CheckedListBox

Post by dank42 »

Thanks :)
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Select All Items in a CheckedListBox

Post by dank42 »

Cannot convert argument "index", with value: "VPN", for "SetItemChecked" to type "System.Int32": "Cannot convert value "VPN" to
ERROR: type "System.Int32". Error: "Input string was not in a correct format.""

I get the above for each item.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Select All Items in a CheckedListBox

Post by jvierra »

Sorry -

Code: Select all

# check all items
(0..($checkedlistbox1.Items.Count -1)) | %{ $checkedlistbox1.SetItemChecked($_,$true)}
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Select All Items in a CheckedListBox

Post by dank42 »

Works a treat, thank you.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked