Check if an item in a combobox already exists

Ask your PowerShell-related questions, including questions on cmdlet development!
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 4 years and 3 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
byrnecutIT
Posts: 4
Last visit: Fri Jan 03, 2020 12:41 am

Check if an item in a combobox already exists

Post by byrnecutIT »

Hi all,

What's the best way to see if an item already exists in a Combobox before adding it? I've tried

foreach ($obj in $Combobox.Items)

as well as $Combobox.FindString

Both don't seem to work. This may be simple but there's not much information on Google on how to do it.

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

Re: Check if an item in a combobox already exists

Post by jvierra »

Code: Select all

if($conbobox.Items | Where-Object( $_ -eq 'myitem'}){
      # found
}else{
     # not found
}
This topic is 4 years and 3 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