import-csv and combobox

Welcome Forums General PowerShell Q&A import-csv and combobox

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #105340

    Participant
    Points: 0
    Rank: Member

    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

  • #105341

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    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.

    • #105346

      Participant
      Points: 0
      Rank: Member

      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 ?

  • #105349

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    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.

    • #105350

      Participant
      Points: 0
      Rank: Member

      ok I will see forum Sapien

  • #105364

    Participant
    Points: 225
    Helping Hand
    Rank: Participant

    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'

    'stackoverflow.com/questions/14756752/one-combo-box-filtering-another-combo-box-in-a-wpf-datagrid'

    'codeproject.com/Articles/301678/Step-by-Step-WPF-Data-Binding-with-Comboboxes'

    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.

    'stackoverflow.com/questions/34187010/how-to-bind-3-comboboxes-powershell-and-wpf'

The topic ‘import-csv and combobox’ is closed to new replies.