[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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?
0
Andy Green
Asked:
Andy Green
1 Solution
 
Wayne Taylor (webtubbs)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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now