0

I've created a user control with a simple text box and a corresponding label and added a few custom control properties. When added to a form, I'm trying to loop through all control of this type and evaluate the custom property. In the below, the cntl.MyCustomProperty is not recognized.

I can evaluate the property when I check each user control on the form by name, but not by using the loop below. I would much rather use the loop as it is much cleaner.

Any ideas?

For Each cntl As Control In Me.Controls
            If (TypeOf cntl Is MyUserControl) And cntl.MyCustomProperty = "ABC" Then
                ''Do some stuff
            End If
        Next
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by justMarshall
0

try this:

For Each cntl As Control In Me.Controls
      If (TypeOf cntl Is MyUserControl) AndAlso CType(cntl,MyUserControl).MyCustomProperty = "ABC" Then
             ''Do some stuff
      End If
Next

Edited by GeekByChoiCe: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.