I am looking for a way to display a selected value (i.e., "Peter") in a combo box upon form load with PowerShell. When the form loads, the combo box is blank. Also, I don't think my code is very efficient because I am using "foreach" and a loop counter. Here is the code I am using. All assistance is appreciated.
[array]$ComboBoxArray = "John", "Peter", "Paul"
.
.
.
$Loop_CNT = 0
foreach ($Item in $ComboBoxArray)
{
[void] $ComboBox.Items.Add($Item)
if ($Item -eq "Peter")
{
$ComboBox.SelectedIndex = $Loop_CNT
$ComboBox.Text = $Item
}
$Loop_CNT = $Loop_CNT + 1
} # End of foreach loop