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?
 
Wayne Taylor (webtubbs)Connect With a Mentor AstronautCommented:
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
 
Wayne Taylor (webtubbs)AstronautCommented:
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
All Courses

From novice to tech pro — start learning today.