Solved

Combobox, SelectedIndexChanged Get Index

Posted on 2016-10-29
2
36 Views
Last Modified: 2016-10-30
I have a combo-box with static data and when I select an item in the combobox I want to return the Index into the Array.

 Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If (String.IsNullOrEmpty(ComboBox1.Text)) Then
            MessageBox.Show("No Item is Selected")

        Else
            Label5.Text = " You have Selected :" + ComboBox1.TabIndex.ToString
        End If

    End Sub

Open in new window


ComboBox with Array
 'ComboBox1
        '
        Me.ComboBox1.FormattingEnabled = True
        Me.ComboBox1.Items.AddRange(New Object() {"Has The Screen Got Wet in the last 24 Hours", "Is the Screen of the device cracked", "Is your Screen Slow and crashing?", "Is your Touch Screen not responding", "Do you have Sufficient Funds in your account to send Text Message", "Are you able to recieve and send text messages", "Do you have sufficient funds in your account", "are you connected to WIFI or have sufficient funds to use data"})
        Me.ComboBox1.Location = New System.Drawing.Point(34, 186)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(470, 21)
        Me.ComboBox1.TabIndex = 17
        '

Open in new window

0
Comment
2 Comments
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 41865649
ComboBox1.TabIndex.ToString will return what u'r asking for - TabIndex which is 17 for combo1.
If you need item index (integer), use ComboBox1.SelectedIndex (-1 means nothing selected).
Since all objects in your combo are strings, you can use ComboBox1.SelectedItem.ToString to get selected item text. You can get same string using ComboBox1.Text property since SelectedIndexChanged fired AFTER ComboBox change it's text to one you choose.
0
 
LVL 79

Author Closing Comment

by:David Johnson, CD, MVP
ID: 41865668
Thank you it was the ComboBox1.SelectedIndex that I couldn't find when break pointing the code
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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

18 Experts available now in Live!

Get 1:1 Help Now