Link to home
Start Free TrialLog in
Avatar of bhlang
bhlangFlag for Canada

asked on

Lock Text Boxes (VB 2005)

I have a set of Text Boxes on a form that I am trying to lock. They're in various containers on that form however, so I have to do multiple loops to get them all. Is there an easier way to do this?

Here's my code (Thanks to carl_tawn for showing me the CType method):

    Private Sub LockFields(ByVal Lock As Boolean)
        For Each ctrl As Control In Me.SplitContainer2.Panel2.Controls
            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).ReadOnly = Lock
            End If
        Next
        For Each ctrl As Control In Me.TabPage1.Controls
            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).ReadOnly = Lock
            End If
        Next
        For Each ctrl As Control In Me.TabPage2.Controls
            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).ReadOnly = Lock
            End If
        Next
    End Sub

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Do you want all TextBoxes on your form to be locked?  Or just the ones in those containers?
Avatar of bhlang

ASKER

I want to lock all the text boxes on the form in this case.
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhlang

ASKER

Oops. Forgot to award the points. Sorry.