Old ladyHow Big Is Your Package?
Size up and convert your DTS package to SSIS. If you have the biggest DTS package, win a gift card and certificate of a world record package size.  
Clear all text boxes with a loop in Tabs - Mike Davis
in

Pragmatic Works

Mike Davis

Clear all text boxes with a loop in Tabs

In my last Blog entry I wrote about how to clear all text boxes in a windows form. But what if that form has tabs? Then you will need to set up a loop inside of loop inside of a loop. I know it seems confusing, but it is much better than the alternative of coding every text box name on every tab page into a reset or clear button. Especially if you have hundreds of text boxes. Here is the code to do it.


        Dim x As Integer
        For x = 0 To Me.Controls.Count - 1

            If TypeOf Me.Controls.Item(x) Is TextBox Then
                Me.Controls.Item(x).Text = ""
            End If

            If TypeOf Me.Controls.Item(x) Is TabControl Then

                Dim tabControl As TabControl = Me.Controls.Item(x)
                Dim z As Integer

                For z = 0 To tabControl.TabCount() - 1

                    Dim TabPage As TabPage = tabControl.TabPages(z)
                    Dim y As Integer

                    For y = 0 To TabPage.Controls.Count - 1
                        If TypeOf TabPage.Controls.Item(y) Is TextBox Then
                            TabPage.Controls.Item(y).Text = ""
                        End If
                    Next

                Next

            End If

        Next

We start out with a loop on the current page controls and clearing any text boxes there, then we detect if the control is a tab control. Then we start a loop inside of that for each tab page. Then a loop in that for each control on the tab page.  I created variables with the name of the control to make it easier to read. You can leave this out and just use the name in the precdeing loop but it can get ugly, like:  Me.Controls.Item(x).TabPages(z).Controls.Item(y).Text = "". This would be the end results if we did not you the variables.

 You can use this same concept with any container on a form.

Comments

No Comments

About Mike Davis

Mike Davis, is a developer, consultant, trainer, and mentor who is enthusiastic about developing robust application for SQL server. He has expertise in many areas of Business Intelligence including Integration Services, Reporting Services, Database Administration, and .Net Software Development. Mike has created BI and software solutions for financial institutions and pragmatic works. He has developed .Net applications for SQL add-ons as well as standalone applications. Mike also participates as a speaker at events like SQL Server 2008 launch and SQL server user group meetings .
Copyright Pragmatic Works
Powered by Community Server (Non-Commercial Edition), by Telligent Systems