How to enumerate textbox controls on a form?

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 11 years and 1 month 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.
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

How to enumerate textbox controls on a form?

Post by rtiel1 »

How can I enumerate all textboxes on a form? I want to clear all textboxes on a form with one click without having to specify each control. When I use eg $testform.Controls it returns only buttons, groupboxes etc but no text- or comboboxes. I'm using Powershell Studio 2012 latest version.

Thnx Remco
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

How to enumerate textbox controls on a form?

Post by davidc »

The Controls property only contains the direct child controls. So if the textboxes are located in a group box or any other container control, then you will need to use the groupbox's Controls property instead.

foreach($control in $groupBox.Controls)
{
if($control -is [System.Windows.Forms.TextBox])
{
$control.Enabled = $false
}
}

Note: You can tell that a control is a container by using the following:

if( $control -is [System.Windows.Forms.ContainerControl])
....

David
David
SAPIEN Technologies, Inc.
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

How to enumerate textbox controls on a form?

Post by rtiel1 »

Thnx for the explanation, another thing learned today :-)
This topic is 11 years and 1 month 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.