TAB on matched string

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 6 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
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

TAB on matched string

Post by localpct »

I've figured out how to send a TAB after it's matched the string I need it to

$textbox2_TextChanged={
#TODO: Place custom script here
if ($textbox2.Text.Trim() -match '[PC]{2}\d{6}')
{
$wshell.SendKeys('{tab}')
}
}

That's great.. So my question, is is there an easier way to tab through my next 9 boxes?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TAB on matched string

Post by jvierra »

You can set the form to move through the tabs automatically in the order you set.
Place your test in the "Validating" event. When the event validates successfully the next control will be automatically selected.

If you want a different control to be next use the "Select()" method on the control you want to switch to. Place the code in the "Validated" event.

$controlname.Select()

We seldom ever use "SendKeys" as it can be unreliable.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: TAB on matched string

Post by localpct »

Validateevent of the textbox?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TAB on matched string

Post by jvierra »

localpct wrote:Validateevent of the textbox?
The Validate and Validating events of ANY "forms control" control the behavior of the form. As long as "Validating" returns "$_.Cancel - $true" the control will remain in focus. When it doesn't the "Validated event will fire allowing us to determine what happens next. The default behavior is to select the next control in the tab order.

Look up and study the forms events control flow documentation. Understanding it can save you hundreds of lines of code
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: TAB on matched string

Post by localpct »

jvierra wrote:
localpct wrote:Validateevent of the textbox?
The Validate and Validating events of ANY "forms control" control the behavior of the form. As long as "Validating" returns "$_.Cancel - $true" the control will remain in focus. When it doesn't the "Validated event will fire allowing us to determine what happens next. The default behavior is to select the next control in the tab order.

Look up and study the forms events control flow documentation. Understanding it can save you hundreds of lines of code
I've not seen this holy "forms events control floe documentation"

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

Re: TAB on matched string

Post by jvierra »

Sorry:

Look up and study the "forms events control flow" documentation.

Language is tricky. I get sloppy at ties.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TAB on matched string

Post by jvierra »

User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: TAB on matched string

Post by localpct »

jvierra wrote:Sorry:

Look up and study the "forms events control flow" documentation.

Language is tricky. I get sloppy at ties.
Oh. Well holy was sorta sarcastic.

No worries sir and thanks for the link.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: TAB on matched string

Post by localpct »

So I think I've got this part down. But I feel I'm doing it the wrong/long way. I wasn't sure if I should create a new post as it's a different issue or not but what I'm running into now is keeping fields from the mainform and passing them over to the childform and then taking all of those items ( just textboxes ) and adding them to a CSV.. So here's a break down

I have an project form in progress to address missing computers.

When it first launches it checks against active directory for users of a specific group - this way whenever someone is added to certain managers, the application is automatically updated
The technicians are required to scan their badge to be able to scan a PC. On a single PC, exporting it to a CSV is no problem so for example the CSV looks like this

EmployeeID EmployeeName PCNumber Scanned Location
001 John Smith PC000001 Incident-Deployment


I'd like to create a batch process but I'm not sure how to add a new row in the CSV but also append the techs ID number, name, location etc and only change the PC# for example
  1. EmployeeID      EmployeeName     PCNumber     Scanned Location
  2. 001            John Smith        PC000001      Incident-Deployment
  3. 001            John Smith        PC000072      Incident-Deployment
  4. 001            John Smith        PC000068      Incident-Deployment
  5. 001            John Smith        PC000099      Incident-Deployment
  6. 001            John Smith        PC000101      Incident-Deployment
  7. 001            John Smith        PC000062      Incident-Deployment
  8. 001            John Smith        PC000073      Incident-Deployment
The employee ID, Name and ScannedLocation is from the MainForm but the PCNumber will be from a child form. I can attach the childform for now.
Attachments
BatchScanIT_Public.psf
(45.25 KiB) Downloaded 109 times
Last edited by localpct on Wed Jun 21, 2017 4:11 pm, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TAB on matched string

Post by jvierra »

You need to start a new question and state what you are actually coding and what issue you are not able to resolve.

Without some idea of what your code is trying to do this doesn't make much sense.
This topic is 6 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