Avatar of G Scott
G Scott
Flag for United States of America asked on

Find Custom Controls By Name

So I have created a simple custom control that is made up of a number of labels.  I have given the control some properties so I can assign values to those labels.  I am filling a datatable from SQL and now I want to loop through that datatable and set values to the labels of my custom controls from this dt.  I have done this kind of thing in the past quite easily, however, I can't seem to figure this out with the custom control.

Here is my code for the custom control:
Public Class ctClock
    
    Private myColor As Color
    Private txtMold As String
    Private txtTool As String
    Private txtJCIPart As String
    Private txtCustPart As String
    Private txtOrder As String
    Private txtNumbers As String
    Private txtStatus As String
    Private txtName As String

    Property wholecolor() As Color
        Get
            Return myColor
        End Get
        Set(ByVal value As Color)
            myColor = value
            Me.BackColor = myColor
        End Set
    End Property

    Property Mold() As String
        Get
            Return txtMold
        End Get
        Set(ByVal value As String)
            txtMold = value
            lblMold.Text = txtMold
        End Set
    End Property
    Property Tool() As String
        Get
            Return txtTool
        End Get
        Set(ByVal value As String)
            txtTool = value
            lblTool.Text = txtTool
        End Set
    End Property

    Property JCIPart() As String
        Get
            Return txtJCIPart
        End Get
        Set(ByVal value As String)
            txtJCIPart = value
            lblJCIPart.Text = txtJCIPart
        End Set
    End Property

    Property CustPart() As String
        Get
            Return txtCustPart
        End Get
        Set(ByVal value As String)
            txtCustPart = value
            lblCustPart.Text = txtCustPart
        End Set
    End Property


    Property Order() As String
        Get
            Return txtOrder
        End Get
        Set(ByVal value As String)
            txtOrder = value
            lblOrder.Text = txtOrder
        End Set
    End Property

    Property Numbers() As String
        Get
            Return txtNumbers
        End Get
        Set(ByVal value As String)
            txtNumbers = value
            lblNumbers.Text = txtNumbers
        End Set
    End Property

    Property Status() As String
        Get
            Return txtStatus
        End Get
        Set(ByVal value As String)
            txtStatus = value
            lblStatus.Text = txtStatus
        End Set
    End Property

End Class

Open in new window


And here is what I am trying to do to assign values to my properties:

 Dim i As Integer = 1
        For Each row As DataRow In dt.Rows
            Dim controlName As String
            controlName = "CtClock" & i
            Me.Controls(controlName).Mold = (row("Press").ToString)
            Me.Controls(controlName).Tool = (row("Tool").ToString)
            i = i + 1
        Next row

Open in new window


I have never done a custom control (as you can probably tell from my example - ripped right from the MSDN site).  Thanks for any help you can give me on this.
Visual Basic.NET

Avatar of undefined
Last Comment
G Scott

8/22/2022 - Mon
Carl Tawn

What you have should work ok, as long as your control isn't sat inside another container. Are you getting any errors from your code?
G Scott

ASKER
My intellisense does this:
Error
ASKER CERTIFIED SOLUTION
Carl Tawn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
G Scott

ASKER
Thank you, Carl.  Your safer method worked perfectly!!
Your help has saved me hundreds of hours of internet surfing.
fblack61