Combobox question
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Combobox question
I want to create a form with 2 comboboxes. the first combobox has 3 choices A, B, C depending on what gets chosen the second combobox items will be populated by a variable $A, $B or $C. How to achieve this?
Re: Combobox question
I tried this but the second combobox does not get populated. Where am I going wrong?
$combobox1_SelectedIndexChanged= {
if ($combobox1.SelectedItem -eq 'A' ) { Load-ComboBox $combobox2.Items.add($A) }
ElseIf ($combobox1.SelectedItem -eq 'B') { Load-ComboBox $combobox2.Items.add($B)}
ElseIf($combobox1.SelectedItem -eq 'C') { Load-ComboBox $combobox2.Items.add($C)}
}
$combobox1_SelectedIndexChanged= {
if ($combobox1.SelectedItem -eq 'A' ) { Load-ComboBox $combobox2.Items.add($A) }
ElseIf ($combobox1.SelectedItem -eq 'B') { Load-ComboBox $combobox2.Items.add($B)}
ElseIf($combobox1.SelectedItem -eq 'C') { Load-ComboBox $combobox2.Items.add($C)}
}
Re: Combobox question
Here is the easiest way to reload a second combo.
- $combobox1_SelectedIndexChanged = {
- $items = switch ($combobox1.SelectedItem){
- 'A'{@('A1', 'A2', 'A2')}
- 'B'{@('B1', 'B2', 'B2')}
- 'C'{@('C1', 'C2', 'C2')}
- }
- $combobox2.Items.Clear()
- $combobox2.Items.AddRange($items)
- }
Re: Combobox question
I tried what you suggested and was able to populate the second combobox but the items listed have some extra characters that I have unsuccessfully tried to remove
For Example:
What I expected to see in the second combo box:
MS Office
Adobe Acrobat
Google Chrome
What gets populated is:
@(Name=MS Office)
@(Name=Adobe Acrobat)
@(Name=Google Chrome)
How do I have it list correctly?
Thanks for your help!
Here is the code:
$comboboxChooseCollType_SelectedIndexChanged= {
$items = switch ($comboboxChooseCollType.SelectedItem)
{
'QA'{ @(Get-CMDeviceCollection | where-object { $PSItem.comment -like "*QA*" } | Select-Object -Property Name) }
'UAC'{ @(Get-CMDeviceCollection | where-object { $PSItem.comment -like "*UAC*" } | Select-Object -Property Name) }
'Production'{ @(Get-CMDeviceCollection | where-object { $PSItem.comment -like "*Production*" } | Select-Object -Property Name) }
}
$comboboxChooseCollection.Items.Clear()
$comboboxChooseCollection.Items.AddRange($items)
For Example:
What I expected to see in the second combo box:
MS Office
Adobe Acrobat
Google Chrome
What gets populated is:
@(Name=MS Office)
@(Name=Adobe Acrobat)
@(Name=Google Chrome)
How do I have it list correctly?
Thanks for your help!
Here is the code:
$comboboxChooseCollType_SelectedIndexChanged= {
$items = switch ($comboboxChooseCollType.SelectedItem)
{
'QA'{ @(Get-CMDeviceCollection | where-object { $PSItem.comment -like "*QA*" } | Select-Object -Property Name) }
'UAC'{ @(Get-CMDeviceCollection | where-object { $PSItem.comment -like "*UAC*" } | Select-Object -Property Name) }
'Production'{ @(Get-CMDeviceCollection | where-object { $PSItem.comment -like "*Production*" } | Select-Object -Property Name) }
}
$comboboxChooseCollection.Items.Clear()
$comboboxChooseCollection.Items.AddRange($items)
Re: Combobox question
Get-CMDeviceCollection | where-object { $PSItem.comment -like "*QA*" } | Select-Object -Property Name
Should be:
Get-CMDeviceCollection | where-object { $PSItem.comment -like "*QA*" } | Select-Object -Expand Name
Should be:
Get-CMDeviceCollection | where-object { $PSItem.comment -like "*QA*" } | Select-Object -Expand Name