Hi,
I have this combobox which I try to load with example data but it says empty!
Please advise.
J.
$MainForm_Load={ #TODO: Initialize Form Controls here } #region Control Helper Functions function Load-ListBox { <# .SYNOPSIS This functions helps you load items into a ListBox or CheckedListBox. .DESCRIPTION Use this function to dynamically load items into the ListBox control. .PARAMETER ListBox The ListBox control you want to add items to. .PARAMETER Items The object or objects you wish to load into the ListBox's Items collection. .PARAMETER DisplayMember Indicates the property to display for the items in this control. .PARAMETER Append Adds the item(s) to the ListBox without clearing the Items collection. .EXAMPLE Load-ListBox $ListBox1 "Red", "White", "Blue" .EXAMPLE Load-ListBox $listBox1 "Red" -Append Load-ListBox $listBox1 "White" -Append Load-ListBox $listBox1 "Blue" -Append .EXAMPLE Load-ListBox $listBox1 (Get-Process) "ProcessName" #> Param ( [ValidateNotNull()] [Parameter(Mandatory=$true)] [System.Windows.Forms.ListBox]$ListBox, [ValidateNotNull()] [Parameter(Mandatory=$true)] $Items, [Parameter(Mandatory=$false)] [string]$DisplayMember, [switch]$Append ) if(-not $Append) { $listBox.Items.Clear() } if($Items -is [System.Windows.Forms.ListBox+ObjectCollection]) { $listBox.Items.AddRange($Items) } elseif ($Items -is [Array]) { $listBox.BeginUpdate() foreach($obj in $Items) { $listBox.Items.Add($obj) } $listBox.EndUpdate() } else { $listBox.Items.Add($Items) } $listBox.DisplayMember = $DisplayMember } function Load-ComboBox { <# .SYNOPSIS This functions helps you load items into a ComboBox. .DESCRIPTION Use this function to dynamically load items into the ComboBox control. .PARAMETER ComboBox The ComboBox control you want to add items to. .PARAMETER Items The object or objects you wish to load into the ComboBox's Items collection. .PARAMETER DisplayMember Indicates the property to display for the items in this control. .PARAMETER Append Adds the item(s) to the ComboBox without clearing the Items collection. .EXAMPLE Load-ComboBox $combobox1 "Red", "White", "Blue" .EXAMPLE Load-ComboBox $combobox1 "Red" -Append Load-ComboBox $combobox1 "White" -Append Load-ComboBox $combobox1 "Blue" -Append .EXAMPLE Load-ComboBox $combobox1 (Get-Process) "ProcessName" #> Param ( [ValidateNotNull()] [Parameter(Mandatory=$true)] [System.Windows.Forms.ComboBox]$ComboBox, [ValidateNotNull()] [Parameter(Mandatory=$true)] $Items, [Parameter(Mandatory=$false)] [string]$DisplayMember, [switch]$Append ) if(-not $Append) { $ComboBox.Items.Clear() } if($Items -is [Object[]]) { $ComboBox.Items.AddRange($Items) } elseif ($Items -is [Array]) { $ComboBox.BeginUpdate() foreach($obj in $Items) { $ComboBox.Items.Add($obj) } $ComboBox.EndUpdate() } else { $ComboBox.Items.Add($Items) } $ComboBox.DisplayMember = $DisplayMember } #endregion $combobox1_SelectedIndexChanged={ #TODO: Place custom script here #Load-ComboBox $combobox1 (Get-Process) "ProcessName" Load-ComboBox $combobox1 "Red" -Append Load-ComboBox $combobox1 "White" -Append Load-ComboBox $combobox1 "Blue" -Append }