Solved

Combox propertyies in .NET

Posted on 2013-06-03
2
281 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
ID: 39217150
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
ID: 39217380
BTW...welcome to the world of .Net!  =)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

860 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