Powershell Get values from nested arrays for Textboxes












0















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()









share|improve this question




















  • 1





    Your code as posted will not run. You have errors with missing closing blocks and = signs. Please adjust and repost in an edit

    – trebleCode
    Nov 15 '18 at 14:27













  • Sorry, but I just posted the necessary code.

    – MoBe
    Nov 15 '18 at 14:37











  • Is using powershell a requirement? I would just go with a winforms project.

    – bradbury9
    Nov 15 '18 at 15:17











  • It is ideal to give us the necessary code to reproduce the problem. While it is sometimes possible to do without it is almost always better to provide a working code set for other users to test with. Especially where forms are concerned. You can drive off people helping as they would need to rebuild the code just so they could start testing.

    – Matt
    Nov 15 '18 at 15:22
















0















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()









share|improve this question




















  • 1





    Your code as posted will not run. You have errors with missing closing blocks and = signs. Please adjust and repost in an edit

    – trebleCode
    Nov 15 '18 at 14:27













  • Sorry, but I just posted the necessary code.

    – MoBe
    Nov 15 '18 at 14:37











  • Is using powershell a requirement? I would just go with a winforms project.

    – bradbury9
    Nov 15 '18 at 15:17











  • It is ideal to give us the necessary code to reproduce the problem. While it is sometimes possible to do without it is almost always better to provide a working code set for other users to test with. Especially where forms are concerned. You can drive off people helping as they would need to rebuild the code just so they could start testing.

    – Matt
    Nov 15 '18 at 15:22














0












0








0








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()









share|improve this question
















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()






arrays powershell user-interface combobox textbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:37







MoBe

















asked Nov 15 '18 at 14:15









MoBeMoBe

12




12








  • 1





    Your code as posted will not run. You have errors with missing closing blocks and = signs. Please adjust and repost in an edit

    – trebleCode
    Nov 15 '18 at 14:27













  • Sorry, but I just posted the necessary code.

    – MoBe
    Nov 15 '18 at 14:37











  • Is using powershell a requirement? I would just go with a winforms project.

    – bradbury9
    Nov 15 '18 at 15:17











  • It is ideal to give us the necessary code to reproduce the problem. While it is sometimes possible to do without it is almost always better to provide a working code set for other users to test with. Especially where forms are concerned. You can drive off people helping as they would need to rebuild the code just so they could start testing.

    – Matt
    Nov 15 '18 at 15:22














  • 1





    Your code as posted will not run. You have errors with missing closing blocks and = signs. Please adjust and repost in an edit

    – trebleCode
    Nov 15 '18 at 14:27













  • Sorry, but I just posted the necessary code.

    – MoBe
    Nov 15 '18 at 14:37











  • Is using powershell a requirement? I would just go with a winforms project.

    – bradbury9
    Nov 15 '18 at 15:17











  • It is ideal to give us the necessary code to reproduce the problem. While it is sometimes possible to do without it is almost always better to provide a working code set for other users to test with. Especially where forms are concerned. You can drive off people helping as they would need to rebuild the code just so they could start testing.

    – Matt
    Nov 15 '18 at 15:22








1




1





Your code as posted will not run. You have errors with missing closing blocks and = signs. Please adjust and repost in an edit

– trebleCode
Nov 15 '18 at 14:27







Your code as posted will not run. You have errors with missing closing blocks and = signs. Please adjust and repost in an edit

– trebleCode
Nov 15 '18 at 14:27















Sorry, but I just posted the necessary code.

– MoBe
Nov 15 '18 at 14:37





Sorry, but I just posted the necessary code.

– MoBe
Nov 15 '18 at 14:37













Is using powershell a requirement? I would just go with a winforms project.

– bradbury9
Nov 15 '18 at 15:17





Is using powershell a requirement? I would just go with a winforms project.

– bradbury9
Nov 15 '18 at 15:17













It is ideal to give us the necessary code to reproduce the problem. While it is sometimes possible to do without it is almost always better to provide a working code set for other users to test with. Especially where forms are concerned. You can drive off people helping as they would need to rebuild the code just so they could start testing.

– Matt
Nov 15 '18 at 15:22





It is ideal to give us the necessary code to reproduce the problem. While it is sometimes possible to do without it is almost always better to provide a working code set for other users to test with. Especially where forms are concerned. You can drive off people helping as they would need to rebuild the code just so they could start testing.

– Matt
Nov 15 '18 at 15:22












1 Answer
1






active

oldest

votes


















0














$SelectedItem=$CB_NDL.SelectedItem
$TB_Postalcode.text = $CB_NDL_Array.$SelectedItem.Postalcode





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321414%2fpowershell-get-values-from-nested-arrays-for-textboxes%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    $SelectedItem=$CB_NDL.SelectedItem
    $TB_Postalcode.text = $CB_NDL_Array.$SelectedItem.Postalcode





    share|improve this answer




























      0














      $SelectedItem=$CB_NDL.SelectedItem
      $TB_Postalcode.text = $CB_NDL_Array.$SelectedItem.Postalcode





      share|improve this answer


























        0












        0








        0







        $SelectedItem=$CB_NDL.SelectedItem
        $TB_Postalcode.text = $CB_NDL_Array.$SelectedItem.Postalcode





        share|improve this answer













        $SelectedItem=$CB_NDL.SelectedItem
        $TB_Postalcode.text = $CB_NDL_Array.$SelectedItem.Postalcode






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 1:26









        NasNas

        1,09517




        1,09517
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53321414%2fpowershell-get-values-from-nested-arrays-for-textboxes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine