[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Lock Text Boxes (VB 2005)

Posted on 2006-03-24
5
Medium Priority
?
314 Views
Last Modified: 2010-04-23
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

0
Comment
Question by:bhlang
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16284949
Do you want all TextBoxes on your form to be locked?  Or just the ones in those containers?
0
 

Author Comment

by:bhlang
ID: 16285116
I want to lock all the text boxes on the form in this case.
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 16285421
   Private Sub LockFields(ByVal thisControl As Control, ByVal Lock As Boolean)
        For Each ctrl As Control thisControl
            If ctrl.HasChildren Then
                LockFields(ctrl, Lock)
            End If
            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).ReadOnly = Lock
            End If
        Next
    End Sub

Call like this

    LockFields(Me, True)

or

    LockFields(Me, False)

Roger
0
 

Author Comment

by:bhlang
ID: 16490077
Oops. Forgot to award the points. Sorry.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question