Form Combobox1 Changing Text in Combobox2

Welcome Forums General PowerShell Q&A Form Combobox1 Changing Text in Combobox2

Viewing 4 reply threads
  • Author
    Posts
    • #253169
      Participant
      Topics: 11
      Replies: 24
      Points: 17
      Rank: Member

      I have created a form that gets data from a JSON config file.  The first combobox gets a list of departments as listed in the JSON file.  Based on what is selected from combobox1, combobox2 should list the titles associated with the selected department.  I have the basics created and can get this to work, however, it is not user friendly.

      The only thing I want my IT users updating is the JSON file.  They should not have to update the Powershell.  What I am having an issue figuring out is how to tell Powershell what department is selected and what titles to get out of the JSON file based on that.

      Here is what I got so far.

      Powershell

      JSON

      • This topic was modified 3 weeks, 1 day ago by Joseph Monarch. Reason: Corrected spelling mistakes
      • This topic was modified 2 weeks, 3 days ago by kvprasoon. Reason: code formatting
      • This topic was modified 2 weeks, 3 days ago by kvprasoon. Reason: Use decode to True as workaround for formating
    • #253184
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Use the selecteditem property in the where clause to search based on what is selected:

    • #254213
      Participant
      Topics: 11
      Replies: 24
      Points: 17
      Rank: Member

      I have that working.  What I am wanting to avoid is hard coding the departments within the Powershell script.

    • #254441
      Participant
      Topics: 11
      Replies: 24
      Points: 17
      Rank: Member

      Scratch my last reply.  I thought what I was looking at was the same thing, just coded differently.  I see the difference now, but cannot get it to work.  Can you go into a little more detail on the PowerShell portion?

       

      Never mind, I figured it out.  I replace the following lines 124-139 with:

      $cb_department_change = {
      $selectedDept = $cb_department.SelectedItem
      foreach ($dept in $configfile | Where{ $_.Department -eq $selectedDept }) {
      $titles = $dept.Groups.Titles | Sort-Object Title
      }
      $cb_title.Items.Clear()
      $cb_title.Text = $null
      $titles.Title | foreach { $cb_title.Items.Add($_) }
      }
      $cb_department.add_SelectedIndexChanged($cb_department_change)
    • #254585
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      Take a look at this:

Viewing 4 reply threads
  • You must be logged in to reply to this topic.