Solved

Combobox, SelectedIndexChanged Get Index

Posted on 2016-10-29
2
22 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 78

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

14 Experts available now in Live!

Get 1:1 Help Now