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.
Post Reply
cristianve
Posts: 2
Joined: Fri Nov 01, 2019 11:02 am

Forms closing and keep checekbox values

Post by cristianve » Thu Nov 07, 2019 11:08 am

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: 7107
Joined: Tue May 29, 2007 4:43 pm

Re: Forms closing and keep checekbox values

Post by Alexander Riedel » Thu Nov 07, 2019 11:19 am

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.

jvierra
Posts: 13949
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Forms closing and keep checekbox values

Post by jvierra » Thu Nov 07, 2019 11:27 am

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
Joined: Fri Nov 01, 2019 11:02 am

Re: Forms closing and keep checekbox values

Post by cristianve » Thu Nov 07, 2019 11:33 am

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: 13949
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Forms closing and keep checekbox values

Post by jvierra » Thu Nov 07, 2019 12:11 pm

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: 13949
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Forms closing and keep checekbox values

Post by jvierra » Thu Nov 07, 2019 11:41 pm

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 4 times

Post Reply