Show a list when a choice is made











up vote
0
down vote

favorite












I'm trying to work around a script Under Windows.Form and I'm a little bit stuck.



I'd like to be able a specific list appears depending on the choice made from the first list, which means that at the start of the script, only one list has to appears and many other available depending of the choice made.



Here's the full script for reference



#Open a Window.
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.text = "Contrôles"
$form.Size = New-Object System.Drawing.Size(1000,700)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,150)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,150)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

#Create the Data table (DataTable).
$table1 = New-Object system.Data.DataTable
$table2 = New-Object system.Data.DataTable

#Define the 2 column (Name, Type).
$colonne1 = New-Object system.Data.DataColumn Choice,([string])
$colonne2 = New-Object system.Data.DataColumn Choice,([string])

#Create columns in the data table.
$table1.columns.add($colonne1)
$table2.columns.add($colonne2)

#Add the data line by line in the data table.
$ligne = $table1.NewRow() #Creation of the new row.
$ligne.Choice = "Service" #In the column Choice we put the value we want.
$table1.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table1.NewRow()
$ligne.Choice = "Software"
$table1.Rows.Add($ligne)
$ligne = $table1.NewRow()
$ligne.Choice = "Other"
$table1.Rows.Add($ligne)

#Add the data line by line in the data table.
$ligne = $table2.NewRow() #Creation of the new row.
$ligne.Choice = "Service Enable" #In the column Choice we put the value we want.
$table2.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table2.NewRow()
$ligne.Choice = "Service Disable"
$table2.Rows.Add($ligne)
$ligne = $table2.NewRow()
$ligne.Choice = "Other"
$table2.Rows.Add($ligne)

#Create the View.
$vu1 = New-Object System.Data.DataView($table1)
$vu1.Sort="Choice ASC" #Tri la colonne "Extension" par ordre croissant.

$vu2 = New-Object System.Data.DataView($table2)
$vu2.Sort="Choice ASC"

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(650,50)
$label.Size = New-Object System.Drawing.Size(280,35)
$label.Text = 'Please enter the information in the space below:'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(650,100)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

#Create the Drop-down list (ComboBox).
$liste1 = New-Object System.Windows.Forms.Combobox
$liste1.Location = New-Object Drawing.Point 20,50
$liste1.Size = New-Object System.Drawing.Size(150, 50)
$liste1.DropDownStyle = "DropDownList"

$liste2 = New-Object System.Windows.Forms.Combobox
$liste2.Location = New-Object Drawing.Point 350,50
$liste2.Size = New-Object System.Drawing.Size(150, 50)
$liste2.DropDownStyle = "DropDownList"

#Associate the Data to the Drop-down list
#To do so, we create a "Binding Context".
$liste1.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste1.DataSource = $vu1 #Assigne the view that contains the sorted Data.
$liste1.DisplayMember = "Choice" #Column that will be displayed (Choice).

$liste2.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste2.DataSource = $vu2 #Assigne the view that contains the sorted Data.
$liste2.DisplayMember = "Choice" #Column that will be displayed (Choice).

#Attach the control to the window.
$form.controls.add($liste1)
$form.controls.add($liste2)

#Show everything.
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()

#Work the code arround.
if ($liste1.DisplayMember= "Service Enable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}

if ($liste1.DisplayMember = "Service Disable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}
Write-Host "ComboBox = " $liste1.DisplayMember
Write-Host "ComboBox = " $liste2.selectedvalue

#Fin.


If anybody have an idea where I could look, it would be great.



Thanks you
Nad










share|improve this question






















  • Unfortunately programming questions are off-topic here but this looks like it is a great fit for our sister site Stack Overflow. You should ask a moderator to migrate your question there.
    – Burgi
    Nov 22 at 16:59















up vote
0
down vote

favorite












I'm trying to work around a script Under Windows.Form and I'm a little bit stuck.



I'd like to be able a specific list appears depending on the choice made from the first list, which means that at the start of the script, only one list has to appears and many other available depending of the choice made.



Here's the full script for reference



#Open a Window.
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.text = "Contrôles"
$form.Size = New-Object System.Drawing.Size(1000,700)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,150)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,150)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

#Create the Data table (DataTable).
$table1 = New-Object system.Data.DataTable
$table2 = New-Object system.Data.DataTable

#Define the 2 column (Name, Type).
$colonne1 = New-Object system.Data.DataColumn Choice,([string])
$colonne2 = New-Object system.Data.DataColumn Choice,([string])

#Create columns in the data table.
$table1.columns.add($colonne1)
$table2.columns.add($colonne2)

#Add the data line by line in the data table.
$ligne = $table1.NewRow() #Creation of the new row.
$ligne.Choice = "Service" #In the column Choice we put the value we want.
$table1.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table1.NewRow()
$ligne.Choice = "Software"
$table1.Rows.Add($ligne)
$ligne = $table1.NewRow()
$ligne.Choice = "Other"
$table1.Rows.Add($ligne)

#Add the data line by line in the data table.
$ligne = $table2.NewRow() #Creation of the new row.
$ligne.Choice = "Service Enable" #In the column Choice we put the value we want.
$table2.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table2.NewRow()
$ligne.Choice = "Service Disable"
$table2.Rows.Add($ligne)
$ligne = $table2.NewRow()
$ligne.Choice = "Other"
$table2.Rows.Add($ligne)

#Create the View.
$vu1 = New-Object System.Data.DataView($table1)
$vu1.Sort="Choice ASC" #Tri la colonne "Extension" par ordre croissant.

$vu2 = New-Object System.Data.DataView($table2)
$vu2.Sort="Choice ASC"

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(650,50)
$label.Size = New-Object System.Drawing.Size(280,35)
$label.Text = 'Please enter the information in the space below:'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(650,100)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

#Create the Drop-down list (ComboBox).
$liste1 = New-Object System.Windows.Forms.Combobox
$liste1.Location = New-Object Drawing.Point 20,50
$liste1.Size = New-Object System.Drawing.Size(150, 50)
$liste1.DropDownStyle = "DropDownList"

$liste2 = New-Object System.Windows.Forms.Combobox
$liste2.Location = New-Object Drawing.Point 350,50
$liste2.Size = New-Object System.Drawing.Size(150, 50)
$liste2.DropDownStyle = "DropDownList"

#Associate the Data to the Drop-down list
#To do so, we create a "Binding Context".
$liste1.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste1.DataSource = $vu1 #Assigne the view that contains the sorted Data.
$liste1.DisplayMember = "Choice" #Column that will be displayed (Choice).

$liste2.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste2.DataSource = $vu2 #Assigne the view that contains the sorted Data.
$liste2.DisplayMember = "Choice" #Column that will be displayed (Choice).

#Attach the control to the window.
$form.controls.add($liste1)
$form.controls.add($liste2)

#Show everything.
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()

#Work the code arround.
if ($liste1.DisplayMember= "Service Enable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}

if ($liste1.DisplayMember = "Service Disable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}
Write-Host "ComboBox = " $liste1.DisplayMember
Write-Host "ComboBox = " $liste2.selectedvalue

#Fin.


If anybody have an idea where I could look, it would be great.



Thanks you
Nad










share|improve this question






















  • Unfortunately programming questions are off-topic here but this looks like it is a great fit for our sister site Stack Overflow. You should ask a moderator to migrate your question there.
    – Burgi
    Nov 22 at 16:59













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to work around a script Under Windows.Form and I'm a little bit stuck.



I'd like to be able a specific list appears depending on the choice made from the first list, which means that at the start of the script, only one list has to appears and many other available depending of the choice made.



Here's the full script for reference



#Open a Window.
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.text = "Contrôles"
$form.Size = New-Object System.Drawing.Size(1000,700)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,150)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,150)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

#Create the Data table (DataTable).
$table1 = New-Object system.Data.DataTable
$table2 = New-Object system.Data.DataTable

#Define the 2 column (Name, Type).
$colonne1 = New-Object system.Data.DataColumn Choice,([string])
$colonne2 = New-Object system.Data.DataColumn Choice,([string])

#Create columns in the data table.
$table1.columns.add($colonne1)
$table2.columns.add($colonne2)

#Add the data line by line in the data table.
$ligne = $table1.NewRow() #Creation of the new row.
$ligne.Choice = "Service" #In the column Choice we put the value we want.
$table1.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table1.NewRow()
$ligne.Choice = "Software"
$table1.Rows.Add($ligne)
$ligne = $table1.NewRow()
$ligne.Choice = "Other"
$table1.Rows.Add($ligne)

#Add the data line by line in the data table.
$ligne = $table2.NewRow() #Creation of the new row.
$ligne.Choice = "Service Enable" #In the column Choice we put the value we want.
$table2.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table2.NewRow()
$ligne.Choice = "Service Disable"
$table2.Rows.Add($ligne)
$ligne = $table2.NewRow()
$ligne.Choice = "Other"
$table2.Rows.Add($ligne)

#Create the View.
$vu1 = New-Object System.Data.DataView($table1)
$vu1.Sort="Choice ASC" #Tri la colonne "Extension" par ordre croissant.

$vu2 = New-Object System.Data.DataView($table2)
$vu2.Sort="Choice ASC"

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(650,50)
$label.Size = New-Object System.Drawing.Size(280,35)
$label.Text = 'Please enter the information in the space below:'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(650,100)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

#Create the Drop-down list (ComboBox).
$liste1 = New-Object System.Windows.Forms.Combobox
$liste1.Location = New-Object Drawing.Point 20,50
$liste1.Size = New-Object System.Drawing.Size(150, 50)
$liste1.DropDownStyle = "DropDownList"

$liste2 = New-Object System.Windows.Forms.Combobox
$liste2.Location = New-Object Drawing.Point 350,50
$liste2.Size = New-Object System.Drawing.Size(150, 50)
$liste2.DropDownStyle = "DropDownList"

#Associate the Data to the Drop-down list
#To do so, we create a "Binding Context".
$liste1.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste1.DataSource = $vu1 #Assigne the view that contains the sorted Data.
$liste1.DisplayMember = "Choice" #Column that will be displayed (Choice).

$liste2.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste2.DataSource = $vu2 #Assigne the view that contains the sorted Data.
$liste2.DisplayMember = "Choice" #Column that will be displayed (Choice).

#Attach the control to the window.
$form.controls.add($liste1)
$form.controls.add($liste2)

#Show everything.
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()

#Work the code arround.
if ($liste1.DisplayMember= "Service Enable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}

if ($liste1.DisplayMember = "Service Disable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}
Write-Host "ComboBox = " $liste1.DisplayMember
Write-Host "ComboBox = " $liste2.selectedvalue

#Fin.


If anybody have an idea where I could look, it would be great.



Thanks you
Nad










share|improve this question













I'm trying to work around a script Under Windows.Form and I'm a little bit stuck.



I'd like to be able a specific list appears depending on the choice made from the first list, which means that at the start of the script, only one list has to appears and many other available depending of the choice made.



Here's the full script for reference



#Open a Window.
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object Windows.Forms.Form
$form.text = "Contrôles"
$form.Size = New-Object System.Drawing.Size(1000,700)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,150)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,150)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

#Create the Data table (DataTable).
$table1 = New-Object system.Data.DataTable
$table2 = New-Object system.Data.DataTable

#Define the 2 column (Name, Type).
$colonne1 = New-Object system.Data.DataColumn Choice,([string])
$colonne2 = New-Object system.Data.DataColumn Choice,([string])

#Create columns in the data table.
$table1.columns.add($colonne1)
$table2.columns.add($colonne2)

#Add the data line by line in the data table.
$ligne = $table1.NewRow() #Creation of the new row.
$ligne.Choice = "Service" #In the column Choice we put the value we want.
$table1.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table1.NewRow()
$ligne.Choice = "Software"
$table1.Rows.Add($ligne)
$ligne = $table1.NewRow()
$ligne.Choice = "Other"
$table1.Rows.Add($ligne)

#Add the data line by line in the data table.
$ligne = $table2.NewRow() #Creation of the new row.
$ligne.Choice = "Service Enable" #In the column Choice we put the value we want.
$table2.Rows.Add($ligne) #Add a line in the data table.
$ligne = $table2.NewRow()
$ligne.Choice = "Service Disable"
$table2.Rows.Add($ligne)
$ligne = $table2.NewRow()
$ligne.Choice = "Other"
$table2.Rows.Add($ligne)

#Create the View.
$vu1 = New-Object System.Data.DataView($table1)
$vu1.Sort="Choice ASC" #Tri la colonne "Extension" par ordre croissant.

$vu2 = New-Object System.Data.DataView($table2)
$vu2.Sort="Choice ASC"

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(650,50)
$label.Size = New-Object System.Drawing.Size(280,35)
$label.Text = 'Please enter the information in the space below:'
$form.Controls.Add($label)

$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(650,100)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox)

#Create the Drop-down list (ComboBox).
$liste1 = New-Object System.Windows.Forms.Combobox
$liste1.Location = New-Object Drawing.Point 20,50
$liste1.Size = New-Object System.Drawing.Size(150, 50)
$liste1.DropDownStyle = "DropDownList"

$liste2 = New-Object System.Windows.Forms.Combobox
$liste2.Location = New-Object Drawing.Point 350,50
$liste2.Size = New-Object System.Drawing.Size(150, 50)
$liste2.DropDownStyle = "DropDownList"

#Associate the Data to the Drop-down list
#To do so, we create a "Binding Context".
$liste1.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste1.DataSource = $vu1 #Assigne the view that contains the sorted Data.
$liste1.DisplayMember = "Choice" #Column that will be displayed (Choice).

$liste2.BindingContext = New-Object System.Windows.Forms.BindingContext
$liste2.DataSource = $vu2 #Assigne the view that contains the sorted Data.
$liste2.DisplayMember = "Choice" #Column that will be displayed (Choice).

#Attach the control to the window.
$form.controls.add($liste1)
$form.controls.add($liste2)

#Show everything.
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()

#Work the code arround.
if ($liste1.DisplayMember= "Service Enable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}

if ($liste1.DisplayMember = "Service Disable")
{set-service -name RemoteRegistry -ComputerName $textBox.Text -StartupType Automatic}
Write-Host "ComboBox = " $liste1.DisplayMember
Write-Host "ComboBox = " $liste2.selectedvalue

#Fin.


If anybody have an idea where I could look, it would be great.



Thanks you
Nad







powershell list inbox






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 12:06









Nad

1




1












  • Unfortunately programming questions are off-topic here but this looks like it is a great fit for our sister site Stack Overflow. You should ask a moderator to migrate your question there.
    – Burgi
    Nov 22 at 16:59


















  • Unfortunately programming questions are off-topic here but this looks like it is a great fit for our sister site Stack Overflow. You should ask a moderator to migrate your question there.
    – Burgi
    Nov 22 at 16:59
















Unfortunately programming questions are off-topic here but this looks like it is a great fit for our sister site Stack Overflow. You should ask a moderator to migrate your question there.
– Burgi
Nov 22 at 16:59




Unfortunately programming questions are off-topic here but this looks like it is a great fit for our sister site Stack Overflow. You should ask a moderator to migrate your question there.
– Burgi
Nov 22 at 16:59










1 Answer
1






active

oldest

votes

















up vote
1
down vote













1. You have no form / trigger events in your code.



2. You don't have the correct GUI objects in your code to hold a list /
record result.



A form is just a container to hold elements until you add the code behind to make it do something. You have to have a proper GUI object to send that result to.



I am not sure if you are doing this all by hand in the ISE or VSCode or Notepad or whatever, but this is a good first effort. However, what you show, seems to indicate you are not really up to speed on GUI development / general app dev work, as what you are doing is not really unique to PowerShell, but something required for any app development client or web.



So, really, spend some time studying / reviewing general WPF/Winforms development and that form event stuff will be covered.



As for your use case, you need:




  • Define the list GUI object (multiline, ListBox, ListView, datagrid) to hold the results (synch'ing combox boxes mean adding and removing elements on event actions)

  • Define what that list is (text files, db read etc)

  • On the click, change or other form event, read from that list and populate
    the GUI list object


There are many examples of this on this site and all over the web.



Here a good video on GUI development with PowerShell:



powershell populate combobox basing on the selected item on another combobox



From the above discussion (not something to just add to your code without understanding the what's and the why's):



Use a ComboBox.SelectionChangeCommitted Event:

"Occurs when the user changes the selected item and that change is displayed in the ComboBox"
$combobox2_SelectionChangeCommitted={

$Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
foreach ($mailbox in $Mailboxes)
{
$CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
Load-ComboBox $combobox2 $CurrentMailbox -Append
}

}

Use a button:
$button1_Click={

$Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
foreach ($mailbox in $Mailboxes)
{
$CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
Load-ComboBox $combobox2 $CurrentMailbox -Append
}
}


Lastly, using this …



Write-Host "ComboBox = " $liste1.DisplayMember
Write-Host "ComboBox = " $liste2.selectedvalue


… is not something one would do, because the console is not opened to see these results and Write-Host should be avoided except for when using console only text colorizations of other console only formatting scenarios, it also empties the display buffer, so it cannot be sent to anything else. Also, you don't have a GUI object called 'ComboBox' anywhere on the form, so it's not serving any purpose for your use case.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    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',
    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%2fsuperuser.com%2fquestions%2f1376686%2fshow-a-list-when-a-choice-is-made%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








    up vote
    1
    down vote













    1. You have no form / trigger events in your code.



    2. You don't have the correct GUI objects in your code to hold a list /
    record result.



    A form is just a container to hold elements until you add the code behind to make it do something. You have to have a proper GUI object to send that result to.



    I am not sure if you are doing this all by hand in the ISE or VSCode or Notepad or whatever, but this is a good first effort. However, what you show, seems to indicate you are not really up to speed on GUI development / general app dev work, as what you are doing is not really unique to PowerShell, but something required for any app development client or web.



    So, really, spend some time studying / reviewing general WPF/Winforms development and that form event stuff will be covered.



    As for your use case, you need:




    • Define the list GUI object (multiline, ListBox, ListView, datagrid) to hold the results (synch'ing combox boxes mean adding and removing elements on event actions)

    • Define what that list is (text files, db read etc)

    • On the click, change or other form event, read from that list and populate
      the GUI list object


    There are many examples of this on this site and all over the web.



    Here a good video on GUI development with PowerShell:



    powershell populate combobox basing on the selected item on another combobox



    From the above discussion (not something to just add to your code without understanding the what's and the why's):



    Use a ComboBox.SelectionChangeCommitted Event:

    "Occurs when the user changes the selected item and that change is displayed in the ComboBox"
    $combobox2_SelectionChangeCommitted={

    $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
    foreach ($mailbox in $Mailboxes)
    {
    $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
    Load-ComboBox $combobox2 $CurrentMailbox -Append
    }

    }

    Use a button:
    $button1_Click={

    $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
    foreach ($mailbox in $Mailboxes)
    {
    $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
    Load-ComboBox $combobox2 $CurrentMailbox -Append
    }
    }


    Lastly, using this …



    Write-Host "ComboBox = " $liste1.DisplayMember
    Write-Host "ComboBox = " $liste2.selectedvalue


    … is not something one would do, because the console is not opened to see these results and Write-Host should be avoided except for when using console only text colorizations of other console only formatting scenarios, it also empties the display buffer, so it cannot be sent to anything else. Also, you don't have a GUI object called 'ComboBox' anywhere on the form, so it's not serving any purpose for your use case.






    share|improve this answer



























      up vote
      1
      down vote













      1. You have no form / trigger events in your code.



      2. You don't have the correct GUI objects in your code to hold a list /
      record result.



      A form is just a container to hold elements until you add the code behind to make it do something. You have to have a proper GUI object to send that result to.



      I am not sure if you are doing this all by hand in the ISE or VSCode or Notepad or whatever, but this is a good first effort. However, what you show, seems to indicate you are not really up to speed on GUI development / general app dev work, as what you are doing is not really unique to PowerShell, but something required for any app development client or web.



      So, really, spend some time studying / reviewing general WPF/Winforms development and that form event stuff will be covered.



      As for your use case, you need:




      • Define the list GUI object (multiline, ListBox, ListView, datagrid) to hold the results (synch'ing combox boxes mean adding and removing elements on event actions)

      • Define what that list is (text files, db read etc)

      • On the click, change or other form event, read from that list and populate
        the GUI list object


      There are many examples of this on this site and all over the web.



      Here a good video on GUI development with PowerShell:



      powershell populate combobox basing on the selected item on another combobox



      From the above discussion (not something to just add to your code without understanding the what's and the why's):



      Use a ComboBox.SelectionChangeCommitted Event:

      "Occurs when the user changes the selected item and that change is displayed in the ComboBox"
      $combobox2_SelectionChangeCommitted={

      $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
      foreach ($mailbox in $Mailboxes)
      {
      $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
      Load-ComboBox $combobox2 $CurrentMailbox -Append
      }

      }

      Use a button:
      $button1_Click={

      $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
      foreach ($mailbox in $Mailboxes)
      {
      $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
      Load-ComboBox $combobox2 $CurrentMailbox -Append
      }
      }


      Lastly, using this …



      Write-Host "ComboBox = " $liste1.DisplayMember
      Write-Host "ComboBox = " $liste2.selectedvalue


      … is not something one would do, because the console is not opened to see these results and Write-Host should be avoided except for when using console only text colorizations of other console only formatting scenarios, it also empties the display buffer, so it cannot be sent to anything else. Also, you don't have a GUI object called 'ComboBox' anywhere on the form, so it's not serving any purpose for your use case.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        1. You have no form / trigger events in your code.



        2. You don't have the correct GUI objects in your code to hold a list /
        record result.



        A form is just a container to hold elements until you add the code behind to make it do something. You have to have a proper GUI object to send that result to.



        I am not sure if you are doing this all by hand in the ISE or VSCode or Notepad or whatever, but this is a good first effort. However, what you show, seems to indicate you are not really up to speed on GUI development / general app dev work, as what you are doing is not really unique to PowerShell, but something required for any app development client or web.



        So, really, spend some time studying / reviewing general WPF/Winforms development and that form event stuff will be covered.



        As for your use case, you need:




        • Define the list GUI object (multiline, ListBox, ListView, datagrid) to hold the results (synch'ing combox boxes mean adding and removing elements on event actions)

        • Define what that list is (text files, db read etc)

        • On the click, change or other form event, read from that list and populate
          the GUI list object


        There are many examples of this on this site and all over the web.



        Here a good video on GUI development with PowerShell:



        powershell populate combobox basing on the selected item on another combobox



        From the above discussion (not something to just add to your code without understanding the what's and the why's):



        Use a ComboBox.SelectionChangeCommitted Event:

        "Occurs when the user changes the selected item and that change is displayed in the ComboBox"
        $combobox2_SelectionChangeCommitted={

        $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
        foreach ($mailbox in $Mailboxes)
        {
        $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
        Load-ComboBox $combobox2 $CurrentMailbox -Append
        }

        }

        Use a button:
        $button1_Click={

        $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
        foreach ($mailbox in $Mailboxes)
        {
        $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
        Load-ComboBox $combobox2 $CurrentMailbox -Append
        }
        }


        Lastly, using this …



        Write-Host "ComboBox = " $liste1.DisplayMember
        Write-Host "ComboBox = " $liste2.selectedvalue


        … is not something one would do, because the console is not opened to see these results and Write-Host should be avoided except for when using console only text colorizations of other console only formatting scenarios, it also empties the display buffer, so it cannot be sent to anything else. Also, you don't have a GUI object called 'ComboBox' anywhere on the form, so it's not serving any purpose for your use case.






        share|improve this answer














        1. You have no form / trigger events in your code.



        2. You don't have the correct GUI objects in your code to hold a list /
        record result.



        A form is just a container to hold elements until you add the code behind to make it do something. You have to have a proper GUI object to send that result to.



        I am not sure if you are doing this all by hand in the ISE or VSCode or Notepad or whatever, but this is a good first effort. However, what you show, seems to indicate you are not really up to speed on GUI development / general app dev work, as what you are doing is not really unique to PowerShell, but something required for any app development client or web.



        So, really, spend some time studying / reviewing general WPF/Winforms development and that form event stuff will be covered.



        As for your use case, you need:




        • Define the list GUI object (multiline, ListBox, ListView, datagrid) to hold the results (synch'ing combox boxes mean adding and removing elements on event actions)

        • Define what that list is (text files, db read etc)

        • On the click, change or other form event, read from that list and populate
          the GUI list object


        There are many examples of this on this site and all over the web.



        Here a good video on GUI development with PowerShell:



        powershell populate combobox basing on the selected item on another combobox



        From the above discussion (not something to just add to your code without understanding the what's and the why's):



        Use a ComboBox.SelectionChangeCommitted Event:

        "Occurs when the user changes the selected item and that change is displayed in the ComboBox"
        $combobox2_SelectionChangeCommitted={

        $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
        foreach ($mailbox in $Mailboxes)
        {
        $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
        Load-ComboBox $combobox2 $CurrentMailbox -Append
        }

        }

        Use a button:
        $button1_Click={

        $Mailboxes = Get-Mailbox -OrganizationalUnit $ClientSelected
        foreach ($mailbox in $Mailboxes)
        {
        $CurrentMailbox = "{0} ({1})" -f $mailbox.Name, $mailbox.Alias
        Load-ComboBox $combobox2 $CurrentMailbox -Append
        }
        }


        Lastly, using this …



        Write-Host "ComboBox = " $liste1.DisplayMember
        Write-Host "ComboBox = " $liste2.selectedvalue


        … is not something one would do, because the console is not opened to see these results and Write-Host should be avoided except for when using console only text colorizations of other console only formatting scenarios, it also empties the display buffer, so it cannot be sent to anything else. Also, you don't have a GUI object called 'ComboBox' anywhere on the form, so it's not serving any purpose for your use case.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 20 at 21:32

























        answered Nov 19 at 21:52









        postanote

        83513




        83513






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2fsuperuser.com%2fquestions%2f1376686%2fshow-a-list-when-a-choice-is-made%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

            Plaza Victoria

            Puebla de Zaragoza

            Musa