Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

No result when clicking on ComboBox item in PowerShell

I’m creating a GUI from PS script and i’m having an issue with my ComboBox

<ComboBox x:Name="comboBox" HorizontalAlignment="Left" Margin="340,60,0,0" VerticalAlignment="Top" Width="64" Height="27">
                        <ComboBoxItem x:Name="Combo1" Content="DOMAIN1" HorizontalAlignment="Left" Width="63"/>
                        <ComboBoxItem x:Name="Combo2" Content="DOMAIN2" HorizontalAlignment="Left" Width="63"/>
                        <ComboBoxItem x:Name="Combo3" Content="DOMAIN3" HorizontalAlignment="Left" Width="63"/>
                    </ComboBox>

When I select DOMAIN 1 I see in my Textblock "This is DOMAIN1" but for DOMAIN2 and 3 this is not working. What am I doing wrong?

$var_comboBox.Add_SelectionChanged({

 if ($var_Combo1.Content -eq "DOMAIN1")
{ $var_result.Text = write "this is DOMAIN1"
}elseif
 ($var_Combo2.Content -eq "DOMAIN2" )
{ $var_result.Text = write "this is DOMAIN2"}

else{
($var_Combo3.Content -eq "DOMAIN3" )
 $var_result.Text = write "this is DOMAIN3"

}

It is only working for the first statement the other ones are not working..

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The first if case is always true.

You should check the value of the Content property of the SelectedItem:

$var_comboBox.Add_SelectionChanged({

$item = $var_comboBox.SelectedItem.Content

 if ($item -eq "DOMAIN1")
{ $var_result.Text = write "this is DOMAIN1"
}elseif
 ($item -eq "DOMAIN2" )
{ $var_result.Text = write "this is DOMAIN2"}

else{
($item -eq "DOMAIN3" )
 $var_result.Text = write "this is DOMAIN3"

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading