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.
Post Reply
User avatar
dank42
Posts: 53
Joined: Mon Apr 25, 2016 1:08 am
Location: United Kingdom

Select All Items in a CheckedListBox

Post by dank42 » Fri Oct 12, 2018 1:48 am

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.

User avatar
jvierra
Posts: 12771
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Select All Items in a CheckedListBox

Post by jvierra » Fri Oct 12, 2018 4:01 am

Code: Select all

# check all items
(0..($checkedlistbox1.Items.Count -1)) | %{ $checkedlistbox1.SetItemChecked($_,$true)}

User avatar
dank42
Posts: 53
Joined: Mon Apr 25, 2016 1:08 am
Location: United Kingdom

Re: Select All Items in a CheckedListBox

Post by dank42 » Fri Oct 12, 2018 4:16 am

Thanks :)

User avatar
dank42
Posts: 53
Joined: Mon Apr 25, 2016 1:08 am
Location: United Kingdom

Re: Select All Items in a CheckedListBox

Post by dank42 » Fri Oct 12, 2018 4:34 am

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.

User avatar
jvierra
Posts: 12771
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Select All Items in a CheckedListBox

Post by jvierra » Fri Oct 12, 2018 5:31 am

Sorry -

Code: Select all

# check all items
(0..($checkedlistbox1.Items.Count -1)) | %{ $checkedlistbox1.SetItemChecked($_,$true)}

User avatar
dank42
Posts: 53
Joined: Mon Apr 25, 2016 1:08 am
Location: United Kingdom

Re: Select All Items in a CheckedListBox

Post by dank42 » Fri Oct 12, 2018 6:02 am

Works a treat, thank you.

Post Reply