Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 107
  • Last Modified:

Combobox, SelectedIndexChanged Get Index

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
David Johnson, CD, MVP
Asked:
David Johnson, CD, MVP
1 Solution
 
ArkCommented:
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
 
David Johnson, CD, MVPOwnerAuthor Commented:
Thank you it was the ComboBox1.SelectedIndex that I couldn't find when break pointing the code
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now