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
import-csv and combobox
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.
Re: import-csv and combobox
You have to prep the data and add it to the box. Normally we add all data to the first then when the selection changes pule the selected row and fill the second box from the row in the first box.
Give it a try and post back.
Give it a try and post back.
-
- Posts: 18
- Last visit: Thu Apr 18, 2019 7:07 am
Re: import-csv and combobox
Try this my friend, add to the form load section of your script:
$csvlist = import-csv -path 'C:\path to your csv file'
$combobox1.DataSource = [system.Collections.ArrayList]$csvlist
$combobox1.DisplayMember = 'company'
$combobox2.DataSource = [system.Collections.ArrayList]$csvlist
$combobox2.DisplayMember = 'site'
Let me know if it works.
I'm aware my code is more than 3 lines, I really don't understand how adding the code block works... sorry... just joined today...
$csvlist = import-csv -path 'C:\path to your csv file'
$combobox1.DataSource = [system.Collections.ArrayList]$csvlist
$combobox1.DisplayMember = 'company'
$combobox2.DataSource = [system.Collections.ArrayList]$csvlist
$combobox2.DisplayMember = 'site'
Let me know if it works.
I'm aware my code is more than 3 lines, I really don't understand how adding the code block works... sorry... just joined today...
Re: import-csv and combobox
Unfortunately that won't work. The site has to be dependent on the company. We can use a dtatable and a view to get the relation or we can store the sites in CB 1.thatsameer wrote: ↑Fri Aug 03, 2018 1:24 pm Try this my friend, add to the form load section of your script:
$csvlist = import-csv -path 'C:\path to your csv file'
$combobox1.DataSource = [system.Collections.ArrayList]$csvlist
$combobox1.DisplayMember = 'company'
$combobox2.DataSource = [system.Collections.ArrayList]$csvlist
$combobox2.DisplayMember = 'site'
Let me know if it works.
I'm aware my code is more than 3 lines, I really don't understand how adding the code block works... sorry... just joined today...
Re: import-csv and combobox
Combo2 for this CSV would look like this
$list = Combobox1.SelectedItem.Sites -split ';'
$combobox2.Items.Clear()
$combobox2.Items.AddRange($list)
All of this would happen on the CB1 "SelectedIndexChanged" event.
$list = Combobox1.SelectedItem.Sites -split ';'
$combobox2.Items.Clear()
$combobox2.Items.AddRange($list)
All of this would happen on the CB1 "SelectedIndexChanged" event.