Retrun to Form

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 10 years and 2 days 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
User avatar
colby911
Posts: 3
Last visit: Wed May 20, 2015 6:15 am

Retrun to Form

Post by colby911 »

I have been trying to work through some basic error checking in my form and I cannot seem to have the PS script return to the form when the error condition is true. Here is my use case:

I have a list box that I want to ensure that at least one item is selected when the Run button is clicked. If there is not an item selected, I want the background of the list box to turn red and the user to have to select something before it turns normal and the user can proceed. The other way that I have been trying to do is have the Run button disabled until something is selected in the list box. (I actually have two list boxes that I need to have populated before allowing the script to run)

This has been great fun learning this so far, however I am stumped at this point.

Cheers
Dave
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Retrun to Form

Post by jvierra »

Look into Windows Forms validation. There are controls to handle error reporting and events that occur as the control is validated and as the form is validated.

This is a big topic so there is not simple one size fits all. Simply validate in the validating event. Return true/false to allow continuation and use "validated" to enable next or other controls due to a successful validation.

Here are some starter articles on forms validation:
http://www.sapien.com/blog/?s=validation
This topic is 10 years and 2 days 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