I have been struggling to find out if powershell will allow comboboxes to behave like the .net version of comboboxes.
Within .net if you create a combobox, you are able to add a field to the combobox that shows text in the drop down. You can also specify the value for each item you see in that drop down.If i choose World War I from the drop down than i am expecting to be able to grab the value WWI and use it.
World War I
World War II
World War III
I've seen posts here about using the Load-Combobox function but that function doesnt seem to let you set the Value member. Has anyone else run into this? Currently i have a work around to create an array that holds the value member and than based on the selected index for the display member i just choose the same index in my array that is holding the value member. Very cludgy.
Please let me know what you think. Maybe im just going crazy.
Code: Select all
Load-ComboBox $CboDistrictName (Get-ADOrganizationalUnit -Filter '(name -like "*")' -SearchScope OneLevel -SearchBase "OU=Districts,DC=WorldTrade" -ResultPageSize 1000 -properties * | Select Name, description) -DisplayMember name -ValueMember description
This functions helps you load items into a ComboBox.
Use this function to dynamically load items into the ComboBox control.
The ComboBox control you want to add items to.
The object or objects you wish to load into the ComboBox's Items collection.
Indicates the property to display for the items in this control.
Adds the item(s) to the ComboBox without clearing the Items collection.
if($Items -is [Array])
$comboBox.ValueMember = "description"
$comboBox.DisplayMember = "name"
You could just access the property from the selected object:
PowerShell CodeDouble-click the code block to select all.
SAPIEN Technologies, Inc.
Thank you for your help. I just tried that and it worked . I wonder why they only made Value member work with a datasource. I dont feel crazy anymore.
Who is online
Users browsing this forum: No registered users and 1 guest