setselected to True on all items in listbox

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 10 years and 10 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
brianclark
Posts: 23
Last visit: Wed Feb 22, 2023 5:19 pm

setselected to True on all items in listbox

Post by brianclark »

I am in the process of building a test application to learn the product, and potentially help myself out with some daily tasks.
I have a form that after selecting some items I click a button and it populates a listbox. I want to be able to, without manually selecting the items in the listbox, click a button and have it run a function against all items in the listbox.
I know how to do it if I manually select all items, however is there a way using the setselected to automatically select the items, and then run my function against that?

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

Re: setselected to True on all items in listbox

Post by jvierra »

PowerShell Code
Double-click the code block to select all.
foreach($item in $listbox1.Items){
     # do something
}
This topic is 10 years and 10 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