简体   繁体   中英

Powershell Get values from nested arrays for Textboxes

I'm trying to create a gui with comboboxes and textboxes. If the user select a item from the Combobox, the related values from an array should appears in textboxes. Can someone give me a clue? I already tried to enumerat thru the arrays and select the key/value pair with -eq, but unfortunately I was not able to solve it this way.

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()


#Arrays
$CB_NDL_Array = @{
                City1 = @{
                    Street = "Test1"
                    Postalcode = "5435"
                }
                City2 = @{
                    Street="Test2"
                    Postalcode="23423"
                }                   
                City3 = @{
                    Street="Test3"
                    Postalcode="234"
                }}   

 $UserManager.controls.AddRange(@($Vorname,$Nachname,$TB_Givenname,$TB_Surname,$Anmeldename,$TB_SamAccountName,$Passwort,$TB_Password,$Niederlassung,$CB_NDL,$Street,$TB_Streetaddress,$City,$TB_City,$PLZ,$TB_Postalcode,$Buero,$TB_Office,$Abteilung,$TB_Department,$Position,$CB_Title,$Firma,$CB_Company,$Manager,$TB_Manager,$Telefon,$TB_OfficePhone,$Mobile,$TB_Mobile,$UserInfo,$Exchange,$RB_exc_yes,$RB_exc_no,$Email_address,$TB_email_address,$CB_Database,$Database,$B_Create))



$CB_NDL                          = New-Object system.Windows.Forms.ComboBox
$CB_NDL.text                     = ""
$CB_NDL.width                    = 100
$CB_NDL.height                   = 20
$CB_NDL.location                 = New-Object System.Drawing.Point(110,180)
$CB_NDL.Font                     = 'Microsoft Sans Serif,10'
$CB_NDL.SelectedItem


$Street                          = New-Object system.Windows.Forms.Label
$Street.text                     = "Strasse"
$Street.AutoSize                 = $true
$Street.width                    = 25
$Street.height                   = 10
$Street.location                 = New-Object System.Drawing.Point(15,210)
$Street.Font                     = 'Microsoft Sans Serif,10'

$TB_Streetaddress                = New-Object system.Windows.Forms.TextBox
$TB_Streetaddress.multiline      = $false
$TB_Streetaddress.width          = 100
$TB_Streetaddress.height         = 20
$TB_Streetaddress.location       = New-Object System.Drawing.Point(110,210)
$TB_Streetaddress.Font           = 'Microsoft Sans Serif,10'

$City                            = New-Object system.Windows.Forms.Label
$City.text                       = "Ort"
$City.AutoSize                   = $true
$City.width                      = 25
$City.height                     = 10
$City.location                   = New-Object System.Drawing.Point(15,240)
$City.Font                       = 'Microsoft Sans Serif,10'

$TB_City                         = New-Object system.Windows.Forms.TextBox
$TB_City.multiline               = $false
$TB_City.width                   = 100
$TB_City.height                  = 20
$TB_City.location                = New-Object System.Drawing.Point(110,240)
$TB_City.Font                    = 'Microsoft Sans Serif,10'


$PLZ                             = New-Object system.Windows.Forms.Label
$PLZ.text                        = "PLZ"
$PLZ.AutoSize                    = $true
$PLZ.width                       = 25
$PLZ.height                      = 10
$PLZ.location                    = New-Object System.Drawing.Point(15,270)
$PLZ.Font                        = 'Microsoft Sans Serif,10'

$TB_Postalcode                   = New-Object system.Windows.Forms.TextBox
$TB_Postalcode.multiline         = $false
$TB_Postalcode.width             = 100
$TB_Postalcode.height            = 20
$TB_Postalcode.location          = New-Object System.Drawing.Point(110,270)
$TB_Postalcode.Font              = 'Microsoft Sans Serif,10' 

$CB_NDL.Add_SelectedIndexChanged({
$TB_City.text = $CB_NDL.SelectedItem
$TB_Postalcode.text = $CB_NDL_Array.values | Where-Object{$CB_NDL.SelectedItem} | Where CB_NDL_Array.$_.key -eq "Postalcode"  })

 foreach ($NDL in $CB_NDL_Array.keys){
 $CB_NDL.items.AddRange("$NDL")
 }

foreach ($Title in $CB_Title_Array){
    $CB_Title.items.add("$Title")
    }

foreach ($Company in $CB_Company_Array){
    $CB_Company.items.add("$Company")
    }                                                      
   [void]$UserManager.ShowDialog()
$SelectedItem=$CB_NDL.SelectedItem
$TB_Postalcode.text = $CB_NDL_Array.$SelectedItem.Postalcode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM