Support Forums

function Load-ToolStripComboBox

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
User avatar
hopkins2007
Posts: 5
Joined: Thu Mar 27, 2014 2:15 pm

function Load-ToolStripComboBox

Postby hopkins2007 » Fri Jan 29, 2016 1:27 pm

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 {
<#
.SYNOPSIS
This functions helps you load items into a ToolStripComboBox.

.DESCRIPTION
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.

.EXAMPLE
Load-ToolStripComboBox $ToolStripComboBox1 "Red", "White", "Blue"

.EXAMPLE
Load-ToolStripComboBox $ToolStripComboBox1 "Red" -Append
Load-ToolStripComboBox $ToolStripComboBox1 "White" -Append
Load-ToolStripComboBox $ToolStripComboBox1 "Blue" -Append

.EXAMPLE
Load-ToolStripComboBox $ToolStripComboBox1 (Get-Process) "ProcessName"
#>
Param (
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
[System.Windows.Forms.ToolStripComboBox]$ToolStripComboBox,
[ValidateNotNull()]
[Parameter(Mandatory = $true)]
$Items,
[Parameter(Mandatory = $false)]
[string]$DisplayMember,
[switch]$Append
)

if (-not $Append) {
$ToolStripComboBox.Items.Clear()
}

if ($Items -is [Object[]]) {
$ToolStripComboBox.Items.AddRange($Items)
} elseif ($Items -is [Array]) {
$ToolStripComboBox.BeginUpdate()
foreach ($obj in $Items) {
$ToolStripComboBox.Items.Add($obj)
}
$ToolStripComboBox.EndUpdate()
} else {
$ToolStripComboBox.Items.Add($Items)
}
}
User avatar
hopkins2007
Posts: 5
Joined: Thu Mar 27, 2014 2:15 pm

Re: function Load-ToolStripComboBox

Postby hopkins2007 » Fri Jan 29, 2016 1:28 pm

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.
User avatar
DevinL
Site Admin
Posts: 570
Joined: Mon Aug 17, 2015 2:25 pm

Re: function Load-ToolStripComboBox

Postby DevinL » Fri Jan 29, 2016 3:38 pm

Thanks for bringing this to our attention, I'll be sure to pass this on to the dev team.
DevinL
SAPIEN Technologies, Inc.

Return to “PowerShell Studio”

Who is online

Users browsing this forum: localpct and 2 guests