Hello, i am building a form with powershell studio 2021, i have a TextBox with a label : Firstname and another TextBox with a label : Lastname. Then, i have two CheckBoxes, one with a label : FirstName lastName and another one with a label : Lastname FirstName.
i am trying to recover the click event of the checkbox in my script in order to display FirstName lastName or Lastname FirstName
My script :
Switch ($DisplayName)
{
$CheckBox1ADCreaDisplayName_Click { $DisplayName = $GivenName + " " + $Surname }
$CheckBox2ADCreaDisplayName_Click { $DisplayName = $Surname + " " + $GivenName }
}
My problem, when i put only the line 1 of the switch i recover the displayName but when i put the second line i don't recover the displayName. i don't know if anybody can help me ?
recover click event of checkbox
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: recover click event of checkbox
You cannot update a non-glbal variable in a function or event directly. The variable besing accessed is out of scope.
Why would you use two checkboxes to swap and unswap two strings. You can just use on box and check if it is checked.
Why would you use two checkboxes to swap and unswap two strings. You can just use on box and check if it is checked.
Code: Select all
if($CheckBox1ADCreaDisplayName.Checked){
$textbox.Text = $GivenName + " " + $Surname
}else{
$textbox.Text = $Surname + " " + $GivenName
}
Re: recover click event of checkbox
Hello jvierra, thank you very much for your help, i just tested with $displayName instead of $textbox.Text and everything is working, I had to try with an if and else but I had put _IsClick instead of .Checked. Thanks again and very good day