Solved

Combox propertyies in .NET

Posted on 2013-06-03
2
277 Views
Last Modified: 2013-06-03
Hi Experts,
I have three comboboxes in my .NET application.  I want to name the comboboxes the same (i.e. cboTEST), and give each a different INDEX number (i.e.  cboTEST(0), cboTEST(1), and cboTEST(3)).  How can I do this in .NET?  I used to be able to do this in VB6.

Thanks in advance,
mrotor
0
Comment
Question by:mainrotor
  • 2
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
You don't need control arrays in VB.Net.

The Index in VB6 allowed you to identify which control fired the event.  In VB.Net, you can wire up multiple controls to the same handler and then use the "sender" parameter to determine which control fired the event.

You can do this by adding more than one control to the "Handles" clause at the end of the handler like this:
    Private Sub ComboBoxes_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged, ComboBox3.SelectedIndexChanged
        Dim cb As ComboBox = DirectCast(sender, ComboBox)
        If cb.SelectedIndex <> -1 Then
            Debug.Print(cb.Name & " --> " & cb.SelectedIndex & ": " & cb.SelectedItem)
        End If
    End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
BTW...welcome to the world of .Net!  =)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

762 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

6 Experts available now in Live!

Get 1:1 Help Now