Search code examples
vb.netcompact-framework

User control property not reachable from indirect call


I try to do some actions on many of my controls during a sub. However I have some troubles to access to properties of my custom UserControl. Here is part of generic code:

        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is CheckBox Then
                CheckBoxes_CheckStateChanged(ctrl, e)
            End If
            If TypeOf ctrl Is MyUserControl Then
                ctrl.MyProperty = true
            End If
        Next

This is working properly for CheckBox part but MyUserControl part is not usable: MyProperty is not proposed or not reachable.

How can I reach and affect a value to the property of my custom UserControl in an automatic way?

PS: I work on compact framework


Solution

  • You need to cast ctrl as its type is control

    If TypeOf ctrl Is MyUserControl Then
        CType(ctrl, MyUserControl).MyProperty = true
    End If