Results 1 to 2 of 2

Thread: ComboBox Help

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Question ComboBox Help

    How to I have an if statement depending on the combo box selection? I get this message:
    Conversion from string "Clear" to type 'Double' is not valid.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If ComboBox1.SelectedIndex = "Clear" Then
                TextBox1.Clear()
            ElseIf ComboBox1.SelectedIndex = "Disable" Then
                TextBox1.Enabled = False
            ElseIf ComboBox1.SelectedIndex = "Both" Then
                TextBox1.Clear()
                TextBox1.Enabled = False
            End If
        End Sub
    Thanks in advance for the help.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ComboBox Help

    The SelectedIndex property returns the index of the selected item, which is an Integer N in the range 0 <= N < Items.Count. If you want the actual text displayed in the control then use the Text property. You might also use the SelectedItem or SelectedValue property, which may both contain the same value as the Text property but may not, depending on the circumstances.

    By the way, you would also be better to use a Select Case statement than If...ElseIf in that situation.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width