Checkbox Validation

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 5 years and 9 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
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Checkbox Validation

Post by dank42 »

Hi,

The title might be a bit misleading on this one.

I am trying to build a string and output it to a variable called $Query based on what checkboxes are ticked.

Each of my checkboxes have a textbox beneath them, it's the content of each textbox that I want in my string but only if the checkbox is ticked. (I have added an event to each checkbox so that when the checkstate chnages the texbox is either visible or not visible)

e.g.

$checkbox_Subject_CheckedChanged={

if ($checkbox_Subject.Checked -eq $true)
{

$textbox_subject.Visible = $true

}else {
$textbox_subject.Visible = $false
}
}

Example format of query "{To:$To AND Subject:$Subject}"

$Search = Get-Mailbox | Search-Mailbox -SearchQuery $Query

So when I click my "build" button it will output the contents of the textboxes to a string

Because they are the checkbox and the textbox are separate, it is throwing me off...
Last edited by dank42 on Tue Jun 26, 2018 7:55 am, edited 2 times in total.
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Checkbox Validation

Post by dank42 »

GUI.gif
GUI.gif (174.29 KiB) Viewed 2249 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkbox Validation

Post by jvierra »

You will have to test the checkboxes for checked and select the text for all that are checked.
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Checkbox Validation

Post by dank42 »

Okay yeah I've got it working ish...

Just on the back of this, how do take the date from the datetimepicker to a string?

I have set a custom format as MM/dd/yyyy but if I do $ToDate = $datetimepicker_ToDate.ToString() I get this:

System.Windows.Forms.DateTimePicker, Value: 13/06/2018 16:54:34

I just want the MM/dd/yyyy without the hh:mm:ss
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Checkbox Validation

Post by dank42 »

Got it:

$FromDate = $datetimepicker_FromDate.Text | Get-Date -Format MM/dd/yyyy
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Checkbox Validation

Post by jvierra »

To use a custom for at you have to do two things. You have to set a "CustomFormat and you have to set "Format" to "Custom".

$datetimepicker_FromDate.CustomFormat = 'MM/dd/yyyy'
$datetimepicker_FromDate.Format = 'Custom'


To retrieve the date object we would do this:
$datetimepicker_FromDate.Value

To reformat the date object
$datetimepicker_FromDate.Value.ToString('dd-MM-yyyy')
User avatar
dank42
Posts: 61
Last visit: Tue Apr 26, 2022 7:49 am

Re: Checkbox Validation

Post by dank42 »

Brilliant, thank you :)
This topic is 5 years and 9 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