Controls ReadOnly property?

I have this little snipped of code iterates through all the controls on this form. But while it gives me the control it does not expose the RealOnly or property or the Clear method. What am I doing wrong?

        Dim cControl As Control
        For Each cControl In Me.Controls
            If (TypeOf cControl Is TextBox) Or (TypeOf cControl Is CheckBox) Then

-->>>                I would like to have cControl.ReadOnly = False but it's not exposed here !!!

            End If
        Next cControl
LVL 1
Lisa0812Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
ReadOnly is not a method associated with a Control, but with the individual controls. Try this instead....
For Each cControl As Control In Me.Controls
    If (TypeOf cControl Is TextBox) Then
        CType(cControl, TextBox).ReadOnly = False
    ElseIf (TypeOf cControl Is CheckBox) Then
        CType(cControl, CheckBox).ReadOnly = False
    End If
Next cControl

Open in new window

0
Wayne Taylor (webtubbs)Commented:
Actually, a CheckBox control does not have a ReadOnly property. You might like to use the Enabled property instead, which, incidentally is a method of a Control object....
For Each cControl As Control In Me.Controls
    If (TypeOf cControl Is TextBox) Then
        CType(cControl, TextBox).ReadOnly = False
    ElseIf (TypeOf cControl Is CheckBox) Then
        CType(cControl, CheckBox).Enabled = True
    End If
Next cControl

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.