Change combobox selected item based on selected item of another combobox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Locked
MoneySolver
Posts: 7
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Tue Dec 31, 2019 7:43 am

Change combobox selected item based on selected item of another combobox

Post by MoneySolver »

I'm looking for assistance on the logic for the following. Please read this request carefully as a lot of people misunderstand what I'm asking.

I have two comboboxes that are already pre-populated with items (powershell objects).
I want the second combobox's selected item to be determined based on what is chosen in the first combobox

Example:
Combobox 1 Items (job titles): helpdesk,sales,servicing
helpdesk.manager = "john smith"
sales.manager = "Mary Jane"
servicing.manager = "jesse custer"

combobox 2 items (managers): john smith,mary jane,jesse custer

if user selects helpdesk in combobox 1, i want combobox 2 to automatically change to john smith.

MoneySolver
Posts: 7
Joined: Tue Dec 31, 2019 7:43 am

Re: Change combobox selected item based on selected item of another combobox

Post by MoneySolver »

This is solved. I stumbled across the findstring method which returns the index number. I then can put that into the combobox.selectedindex property. from my testing, I can only leverage the selectedindex property. trying to set the selectedtext gives weird and inconsistent results. on top of that, if the dropdown style is set to dropdownlist then you can't set selectedtext at all.

This is what worked for me.
$cmbbx_Manager.SelectedIndex = $cmbbx_Manager.FindString($cmbbx_Role.SelectedItem.manager)

Locked