Check if an item in a combobox already exists

Ask your Windows 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.
Locked
daveyc
Posts: 4
Joined: Thu Jan 31, 2019 9:25 am

Check if an item in a combobox already exists

Post by daveyc » Wed Dec 11, 2019 1:22 am

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: 14155
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Check if an item in a combobox already exists

Post by jvierra » Wed Dec 11, 2019 1:29 am

Code: Select all

if($conbobox.Items | Where-Object( $_ -eq 'myitem'}){
      # found
}else{
     # not found
}

Locked