Concatenate 2 strings to make a control name

Hi Experts

How would I concatenate 2 strings to make a form control that I can reference with code.

I have a form with several combo box controls, I want a generic fill routine where I pass in the control name and it gets filled.

Here is my routine:

    Private Sub Lookup_Fill(ByVal strType As String)

        Dim lf As New clsLookups
        Dim dt As DataTable = lf.DoLookup(strType)

        Dim FormControl = strType
        With FormControl
           .DataSource = dt
            .DisplayMember = "LookUpValue"
            .SelectedIndex = 0
        End With

    End Sub

This is how I call:
 Lookup_Fill("Status")

I pass the variable into a proc that return a list (That works OK) I hit a problem when I try to refernce the form control (as a string I guess)

How do  do this?
LVL 3
Andy GreenAsked:
Who is Participating?
 
Wayne Taylor (webtubbs)Connect With a Mentor Commented:
Use the Controls.Find method.

Wayne
    Private Sub Lookup_Fill(ByVal strType As String) 
        Dim lf As New clsLookups
        Dim dt As DataTable = lf.DoLookup(strType) 
        Dim ctrls() As Control = Me.Controls.Find(strType, True)
        If ctrls.Length > 0 Then
            If TypeOf ctrls(0) Is ComboBox Then
                Dim FormControl As ComboBox = CType(ctrls(0), ComboBox)
                With FormControl
                    .DataSource = dt
                    .DisplayMember = "LookUpValue"
                    .SelectedIndex = 0
                End With
            End If
        End If 
    End Sub

Open in new window

0
 
Andy GreenAuthor Commented:
Excellent, Cut and paste and it worked first time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.