import-csv and combobox

Hi all
I need your help

I’ve got a csv file like this:

company;site
company1;site1,site2
company2;site3,site4

and 2 comboxBox

comboBox1 => company
comboBox2 => site

I want import my csv file to list in ComboBox 1 the list of company (company1 company2)

so I use :
import-csv “.source.csv” -delimiter “;” | %{$comboBox1.Items.Add($_.company)}

and accordin to the choose company I want to list in ComboBox2 the list of site of this company

for example comboBox1 = company2, I want in comboBox2 = site3 site4 (one below the other)

Thanks for your help

For the second combo box, you will probably need to re-query the CSV.

Import-CSV whatever.csv -Delim ‘;’ | Where { $_.Company -eq $chosen }

Assuming you’ve placed the selected company name into $chosen.

thanks to toake time to help me.

my script :
$chosen = import-csv “.\test.csv” -delimiter “;” | %{$comboBox1.Items.add($.Company)}
import-csv “.\test.csv” -delimiter ‘;’ | Where {$
.Company -eq $chosen }

but doesn’t work …

where define the $comboBox2 ?

Well, I’m assuming you’ve already defined $comboBox2 in your GUI. If not, I’ll be honest - this is a Q&A forum, and it’s not really a place for a tutorial on something as complex as GUI programming. You might consider using a tool like SAPIEN PowerShell Studio, which simplifies creating the GUI and defining the controls. They also have a very robust support forum to answer questions.

ok I will see forum Sapien

Ditto on Sapien’s PSS, I been using that for years now. Yet, it’s a annual sub cost. well worth it though.

What you are asking has been a thing in GUI (PS notwithstanding) for a long time. SO, not a PS specifc thing but how you handlet the call to your data cource and the form. E,g.:

'social.msdn.microsoft.com/Forums/vstudio/en-US/dc26ec3d-0004-4b99-a7b0-1fe769358cea/filter-combobox-values-based-on-another-combobox-selectedvalue'

xaml - One combo box filtering another combo box in a WPF Datagrid - Stack Overflow

Step by Step WPF Data Binding with Comboboxes - CodeProject

You don’t say how you are doing this GUI, WPF / XAML, but all-in-all, the approach is the same.
Here is a sample of this in action with PS and XAML. It’s not pretty, but it works, thus gives you the idea of what you’d want to do. Remember there are always more elegant / efficient ways to do X or Y. You just need to take your CSV and split the data on load / read into the comboboxes.

xaml - How to bind 3 comboboxes POWERSHELL and WPF - Stack Overflow