?
Solved

How can I dynamically add selection values to my Combobox controls

Posted on 2013-06-03
1
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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