Page 1 of 1

function Load-ToolStripComboBox

Posted: Fri Jan 29, 2016 1:27 pm
by Hopkins2007
Product, version and build: 4.2.99
32 or 64 bit version of product: 64
Operating system: Windows 7
32 or 64 bit OS: 64

I added a MenuStrip to a form project and added several ComboBoxes to it. The first few have hard coded collections in the drop downs, but the last I fill depending on what is selected from the first two. I ran into a problem with the Load-ComboBox function you guys generate when we have a ComboBox in our forms because the -ComboBox parameter is looking for a ComboBox object and the object on the MenuStrip is of type ToolStripComboBox. You may want to add functionality so when a ToolStripComboBox is added to a form, this function is generated with it (note, I removed the DisplayMember parameter, a ToolStripComboBox objects don't have the method).
function Load-ToolStripComboBox {
        This functions helps you load items into a ToolStripComboBox.

        Use this function to dynamically load items into the ToolStripComboBox control.

    .PARAMETER  ToolStripComboBox
        The ToolStripComboBox control you want to add items to.

    .PARAMETER  Items
        The object or objects you wish to load into the ToolStripComboBox's Items collection.
    .PARAMETER  Append
        Adds the item(s) to the ToolStripComboBox without clearing the Items collection.
        Load-ToolStripComboBox $ToolStripComboBox1 "Red", "White", "Blue"
        Load-ToolStripComboBox $ToolStripComboBox1 "Red" -Append
        Load-ToolStripComboBox $ToolStripComboBox1 "White" -Append
        Load-ToolStripComboBox $ToolStripComboBox1 "Blue" -Append
        Load-ToolStripComboBox $ToolStripComboBox1 (Get-Process) "ProcessName"
	Param (
		[Parameter(Mandatory = $true)]
		[Parameter(Mandatory = $true)]
		[Parameter(Mandatory = $false)]
	if (-not $Append) {
	if ($Items -is [Object[]]) {
	} elseif ($Items -is [Array]) {
		foreach ($obj in $Items) {
	} else {

Re: function Load-ToolStripComboBox

Posted: Fri Jan 29, 2016 1:28 pm
by Hopkins2007
Another fix is to remove the object requirement from the Load-ComboBox function you already have, but I think its better to verify your objects.

Re: function Load-ToolStripComboBox

Posted: Fri Jan 29, 2016 3:38 pm
by DevinL
Thanks for bringing this to our attention, I'll be sure to pass this on to the dev team.