Forms closing and keep checekbox values

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.
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
cristianve
Posts: 2
Last visit: Thu Apr 29, 2021 9:37 am

Forms closing and keep checekbox values

Post by cristianve »

Product, version and build: PowerShell Studio 2019 5.6.164
32 or 64 bit version of product: 64 bits
Operating system: Windows 10
32 or 64 bit OS: 64 bits


So I have a multi-form project, in the first one (frmMain), I have some checkbox fields, user select some of them, and then click on 'Next' button and other form (frmAuth) is shown, what I'm trying to achieve is to keep the checkbox selected if the user tries to return to frmMain form.

I've tried Hide(), Close(), Dispose() (this one being my last resource as it only dispose the form).

Here is the frmMain, which is the first one shown, I've selected three checkbox, and click on 'Next' button.
Image

In this form (frmAuth), I click on 'Back' button, and the checkbox are not selected.
Image
Image


Thanks for your help.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Forms closing and keep checekbox values

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms closing and keep checekbox values

Post by jvierra »

Hi Cristian, Your issue is a bit thin. Are you closing the checkbox form before opening the new form. PSF based forms do not exist after they are closed. If you are trying to use multiple data entry forms off a main form then you will have to save the contents and reapply it the next time the form is opened.

PowerShell only supports modal dialogs and Sapien always wraps a form in a function so it is removed from memory after the dialog is closed.
cristianve
Posts: 2
Last visit: Thu Apr 29, 2021 9:37 am

Re: Forms closing and keep checekbox values

Post by cristianve »

Hi, thanks for your answer.

Yes, I'm closing the form before opening the next one, as shown below:
I did this, because showing first and hiding after was not working for me, I don't know why, sincerely I have just two days with PowerShell Studio.

Code: Select all

$btnNext_Click={
	#TODO: Place custom script here
	$frmMain.Hide()
	Show-frmAuth_psf
}
How could I save the contents and reapply? Do you have any docs I can read?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms closing and keep checekbox values

Post by jvierra »

If this is a project then there are variables created for all child form controls so you could pass them as a parameters to the form and apply the contents/

A simpler way to reuse a form is to create a global hash and save the form object and name in the hash during the load of the form. THe second time you want to display the form use the saved form object and "ShowDIalog()" to re-display the saved form. All control contents will be still in the form. This should work with simple controls like checkboxes.

I have been waiting for Sapien to create a child form template that just creates the form and returns the form object which would make this a bit easier but the above method should work with few issues.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms closing and keep checekbox values

Post by jvierra »

In case you haven't figured this out I had some time and knocked together a simple demo project.

Open the project and run it to see the child maintains the values when re-displayed.

The action code is in the "globals.ps1' file and the child is called like this:

Display-ChildForm Show-ChildForm_psf

Only one line needs to be added to the child form load event code:

$formsList.Add($formFunction,$this)
Attachments
Demo-ReusableChild.zip
(127.86 KiB) Downloaded 81 times
This topic is 4 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked