Solved

How can I dynamically add selection values to my Combobox controls

Posted on 2013-06-03
1
300 Views
Last Modified: 2013-06-18
Hi Experts,
I use about 10 Combobox controls in my VB.Net application. The controls names all begin with "cboResult".  I want to loop through all my Combobox controls whose name begins with "cboResult" and add "Yes", "No", and "N/A" as possible selection values (i.e. Items.Add("YES"), etc...).  How can I do this?

Thanks in advance,
mrotor
0
Comment
Question by:mainrotor
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39217447
Try something like...
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        FindCombos(Me)
    End Sub

    Private Sub FindCombos(ByVal cont As Control)
        For Each ctl As Control In cont.Controls
            If ctl.Name.ToUpper.StartsWith("CBORESULT") AndAlso TypeOf ctl Is ComboBox Then
                Dim cb As ComboBox = DirectCast(ctl, ComboBox)
                cb.Items.Add("YES")
                cb.Items.Add("NO")
                cb.Items.Add("N/A")
            ElseIf ctl.HasChildren Then
                FindCombos(ctl)
            End If
        Next
    End Sub

End Class

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now