Solved

How can I dynamically add selection values to my Combobox controls

Posted on 2013-06-03
1
303 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 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 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