The label object with the event “click” does not passthrough the current form value while button objects do

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
Post Reply
ShengPAN
Posts: 5
Last visit: Wed Sep 07, 2022 4:33 am
Answers: 1

The label object with the event “click” does not passthrough the current form value while button objects do

Post by ShengPAN »

This is my first post no clue if this is the correct way of doing this.
But I think there might be a bug on how the form stocks its values or how it passes it during an event.
The label object with the event “click” does not passthrough the current form value while button objects do.
Symptoms:
-if I click next it saves passes the correct current value.
-if I click Label it send the old value from before and not the current value.

For example, I have a $Datagridview object where I have a checkbox. By default, it is unchecked.
If I click my button object next it passes through the current value of that checkbox which is what I want and correct.
However, when clicking on a label with the event “click”. It does not pass the current checkbox value. It sends the old one from before.
To identify this scenario, I set up breakpoints in-between events and used the watcher and debug console to inspect the values of the forms.
  1. $LabelLateral_Click = {
  2.     #When setting the breakpoint here the value is not the current  $DataGridView
  3.     if ($(Set-ValidData -FormValidation CustomizationsForm))
  4.     {
  5.         switch ($this.Text)
  6.         {
  7.             "Readiness" {
  8.                 if ($ReadinessChecksForm)
  9.                 {
  10.                     $CustomizationsForm.TopMost = $false
  11.                     $CustomizationsForm.Visible = $false
  12.                     $ReadinessChecksForm = Show-ReadinessChecksForm_psf
  13.                 }
  14.             }
  15.             "Computer Details" {
  16.                 if ($ComputerDetailsForm)
  17.                 {
  18.                     $CustomizationsForm.TopMost = $false
  19.                     $CustomizationsForm.Visible = $false
  20.                     $ComputerDetailsForm = Show-ComputerDetailsForm_psf
  21.                 }
  22.             }
  23.             "Credentials" {
  24.                 if ($ComputerCredentialsForm)
  25.                 {
  26.                     $CustomizationsForm.TopMost = $false
  27.                     $CustomizationsForm.Visible = $false
  28.                     $ComputerCredentialsForm = Show-ComputerCredentialsForm_psf
  29.                 }
  30.             }
  31.            
  32.             "Summary"{
  33.                 $CustomizationsForm.TopMost = $false
  34.                 $CustomizationsForm.Visible = $false
  35.                 $SummaryForm = Show-SummaryForm_psf
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41. $ButtonNext_Click = {
  42.     #When setting the breakpoint here the value is the current of $DataGridView
  43.     if ($(Set-ValidData -FormValidation CustomizationsForm))
  44.     {
  45.         $CustomizationsForm.TopMost = $false
  46.         $CustomizationsForm.Visible = $false
  47.         $SummaryForm = Show-SummaryForm_psf
  48.     }
  49. }
Does any one else have this scenario?
I appreciate fro any feedbacks.
Thank you in advance.
by ShengPAN » Wed Aug 31, 2022 5:01 am
I found the solution.

My circumstances seem to be by design like this, in windows forms that the label and button works like I described in my problem.

I realized that the button object does not require the validation of the changes made in datagridview -> checkbox and label does.
I used the “CommitEdit()”method from DataGridView object to commit my changes after checking the checkbox.

Code: Select all

$labelClick_Click={
#TODO: Place custom script here

#THE SOLUTION
$datagridview1.CommitEdit('Commit')

if ($this.Font -eq "Microsoft Sans Serif, 8.25pt, style=Bold") {
$this.Font = "Microsoft Sans Serif, 8.25pt"
}
else {
$this.Font = "Microsoft Sans Serif, 8.25pt, style=Bold"
}

$labelReplace.Text = $datagridview1.Rows[0].Cells.Value
}
I thank you for your time, the attempt to solve my issue and the consideration for my post.
Go to full post
jvierra
Posts: 15286
Last visit: Mon Sep 26, 2022 6:41 pm
Answers: 26
Has voted: 4 times
Been upvoted: 27 times

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by jvierra »

Your question is vague and doesn't make much sense. What do you expect to be passed as a value when a label is clicked. Labels cannot be edited. A label does not change its value when clicked. Read you question and try to devise a simple PSF that demonstrates the issue. I am sure the issue is just something that you either misunderstand or maybe a simple coding mistake.

A clear simple example will either lead you to the problem or will help us to understand what the problems is. I am sure the solution is very simple.
jvierra
Posts: 15286
Last visit: Mon Sep 26, 2022 6:41 pm
Answers: 26
Has voted: 4 times
Been upvoted: 27 times

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by jvierra »

There is no need to delete your post. It may be useful to others. It would be helpful if you posted the solution you found. This would also help others looking for solutions to similar issues.
ShengPAN
Posts: 5
Last visit: Wed Sep 07, 2022 4:33 am
Answers: 1

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by ShengPAN »

I split the example in to 2 replies because I can only attach 3 files at the same time.
So, I recreated the scenario in a simpler form.
With 1 form and 4 toolbox objects.
- 1 click label
- 1 button
- 1 label to show the result
- 1 datagridview with checkboxes

Screenshot 1
1.png
1.png (6 KiB) Viewed 622 times
1. I checked the checkbox
2. I press the button “click”
3. The label to show the result replaces the text property as “True” (The value of the checkbox)
Which is correct.

Screenshot 2
2.png
2.png (5.58 KiB) Viewed 622 times
1. I unchecked the checkbox
2. I press the label “Click” (to visualize it, I added an if to change the bold to the font nothing wrong with that)
3. The label to show the result replaces the text property as “True”
Which is incorrect.
Last edited by ShengPAN on Thu Aug 18, 2022 6:46 am, edited 1 time in total.
ShengPAN
Posts: 5
Last visit: Wed Sep 07, 2022 4:33 am
Answers: 1

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by ShengPAN »

Both objects, the button and the labe use the event "click".
When clicking the button the value passes through the current value of that checkbox.
3.png
3.png (136.61 KiB) Viewed 622 times
1. I uncheck the checkbox
2. I click the button
3. Debugconsole to show the current value that goes through the event to update the Result Label ($labelReplace).

When clicking the label it passes through the value before of the current value of that checkbox.
4.png
4.png (145.75 KiB) Viewed 622 times
1. I uncheck the checkbox
2. I click the Label
3. Debugconsole to show the current value that goes through the event to update the Result Label ($labelReplace).

I use break points to illustrate the issue, so it is normal that the result label has not been updated yet.

I also want to add. If I use checkboxes as "standalone"(without a parent datagridview object), everything works fine.
Last edited by ShengPAN on Thu Aug 18, 2022 7:22 am, edited 1 time in total.
ShengPAN
Posts: 5
Last visit: Wed Sep 07, 2022 4:33 am
Answers: 1

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by ShengPAN »

The psf File used.
test.psf
(15.15 KiB) Downloaded 12 times
Powershell studio version 5.8.209
jvierra
Posts: 15286
Last visit: Mon Sep 26, 2022 6:41 pm
Answers: 26
Has voted: 4 times
Been upvoted: 27 times

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by jvierra »

Works fine for me. If you run in the debugger, it will fail because you are freezing the event system and the update doesn't work.
ShengPAN
Posts: 5
Last visit: Wed Sep 07, 2022 4:33 am
Answers: 1

Re: The label object with the event “click” does not passthrough the current form value while button objects do

Post by ShengPAN »

I found the solution.

My circumstances seem to be by design like this, in windows forms that the label and button works like I described in my problem.

I realized that the button object does not require the validation of the changes made in datagridview -> checkbox and label does.
I used the “CommitEdit()”method from DataGridView object to commit my changes after checking the checkbox.
  1. $labelClick_Click={
  2.     #TODO: Place custom script here
  3.    
  4.          #THE SOLUTION
  5.     $datagridview1.CommitEdit('Commit')
  6.    
  7.     if ($this.Font -eq "Microsoft Sans Serif, 8.25pt, style=Bold") {
  8.         $this.Font = "Microsoft Sans Serif, 8.25pt"
  9.     }
  10.     else {
  11.         $this.Font = "Microsoft Sans Serif, 8.25pt, style=Bold"
  12.     }
  13.    
  14.     $labelReplace.Text = $datagridview1.Rows[0].Cells.Value
  15. }
I thank you for your time, the attempt to solve my issue and the consideration for my post.
Post Reply