$checkedlistbox1.CheckedItems - How do i get the checked index number

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 2 years and 2 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
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

$checkedlistbox1.CheckedItems - How do i get the checked index number

Post by lontru »

Image

How do i get the selected index - so instead of getting the "title" getting the number in the list checked.

So above should print out 2 and 4. or 1 and 3 if the index started from 0
by jvierra » Thu Dec 23, 2021 1:24 pm Go to full post
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: $checkedlistbox1.CheckedItems - How do i get the checked index number

Post by jvierra »

User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: $checkedlistbox1.CheckedItems - How do i get the checked index number

Post by lontru »

CheckedIndices was the thing i was looking for thanks.

is there a way to print out all the option in the checkbox
Option 1
Option 2
and so on
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: $checkedlistbox1.CheckedItems - How do i get the checked index number

Post by lontru »

https://docs.microsoft.com/en-us/dotnet ... tBox_Items

found the answer with above link

foreach ($item in $checkedlistbox1.Items) {
Write-Host $item
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: $checkedlistbox1.CheckedItems - How do i get the checked index number

Post by jvierra »

Just enumerate of the "Items" and you will output them in order.
This topic is 2 years and 2 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