bhlang
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
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.
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
Do you want all TextBoxes on your form to be locked? Or just the ones in those containers?
ASKER
I want to lock all the text boxes on the form in this case.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oops. Forgot to award the points. Sorry.